#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct sigaction {
  int dummy;
};
struct TYPE_3__ {
  int ss_flags;
  scalar_t__ ss_size;
  scalar_t__ ss_sp;
};
typedef TYPE_1__ stack_t;
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ENOMEM;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int sigaction(int, struct sigaction *, int /*<<< orphan*/);
int sigaltstack(TYPE_1__ *, int /*<<< orphan*/);
int sigprocmask(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  struct sigaction act;
  sigset_t set;
  stack_t stack;
  errno = 0;
  if (sigaction(0x12345678, &act, 0) != -1 || errno != EINVAL) {
    fprintf(stderr, "sigaction: Expected EINVAL, but got %d\n", errno);
    return 1;
  }
  errno = 0;
  if (sigprocmask(0x12345678, &set, 0) != -1 || errno != EINVAL) {
    fprintf(stderr, "sigprocmask: Expected EINVAL, but got %d\n", errno);
    return 1;
  }
  errno = 0;
  stack.ss_sp = 0;
  stack.ss_size = 0;
  stack.ss_flags = 0x12345678;
  if (sigaltstack(&stack, 0) != -1 || (errno != EINVAL && errno != ENOMEM)) {
    fprintf(stderr, "sigaltstack: Expected EINVAL or ENOMEM, but got %d\n",
            errno);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
movq   $0x0,(%rax)
mov    $0x12345678,%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1190 <main+0x50>
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <main+0x7b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x186>
mov    0x2e0e(%rip),%rax
movq   $0x0,(%rax)
mov    $0x12345678,%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    11fc <main+0xbc>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
je     1227 <main+0xe7>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%rdx
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x186>
mov    0x2da2(%rip),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x12345678,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1060 <sigaltstack@plt>
cmp    $0xffffffff,%eax
jne    1294 <main+0x154>
mov    0x2d69(%rip),%rax
mov    (%rax),%rax
mov    0x2d57(%rip),%rcx
cmp    (%rcx),%rax
je     12bf <main+0x17f>
mov    0x2d4f(%rip),%rax
mov    (%rax),%rax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
je     12bf <main+0x17f>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%rdx
lea    0xda4(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x186>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e80(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0x12345678,%edi
xor    %edx,%edx
call   1040 <sigaction@plt>
mov    (%r14),%rdx
cmp    $0xffffffff,%eax
jne    11f3 <main+0xb3>
mov    0x2e4f(%rip),%r15
cmp    (%r15),%rdx
jne    11f3 <main+0xb3>
movq   $0x0,(%r14)
lea    0x4(%rsp),%rsi
mov    $0x12345678,%edi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    (%r14),%rdx
cmp    $0xffffffff,%eax
jne    1205 <main+0xc5>
cmp    (%r15),%rdx
jne    1205 <main+0xc5>
movq   $0x0,(%r14)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movl   $0x12345678,0x8(%rsp)
12
lea    0x8(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1060 <sigaltstack@plt>
mov    (%r14),%rdx
cmp    $0xffffffff,%eax
jne    11e1 <main+0xa1>
cmp    (%r15),%rdx
je     121f <main+0xdf>
mov    0x2e04(%rip),%rax
cmp    (%rax),%rdx
je     121f <main+0xdf>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
jmp    1215 <main+0xd5>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
jmp    1215 <main+0xd5>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
%struct.TYPE_3__ = type { i32, i64, i64 }
@errno = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"sigaction: Expected EINVAL, but got %d\0A\00"
@.str.1 = [42 x i8] c"sigprocmask: Expected EINVAL, but got %d\0A\00"
@ENOMEM = global i64 0
@.str.2 = [52 x i8] c"sigaltstack: Expected EINVAL or ENOMEM, but got %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
store i32 0, i32* %1
store i64 0, i64* @errno
%5 = call i32 @sigaction(i32 305419896, %struct.sigaction* %2, i32 0)
%6 = icmp ne i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINVAL
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %7, %0
%12 = load i32, i32* @stderr
%13 = load i64, i64* @errno
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i64 %13)
store i32 1, i32* %1
br label %45
15: ; preds = %7
store i64 0, i64* @errno
%16 = call i32 @sigprocmask(i32 305419896, i32* %3, i32 0)
%17 = icmp ne i32 %16, -1
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINVAL
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18, %15
%23 = load i32, i32* @stderr
%24 = load i64, i64* @errno
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %24)
store i32 1, i32* %1
br label %45
26: ; preds = %18
store i64 0, i64* @errno
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 2
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 1
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
store i32 305419896, i32* %29
%30 = call i32 @sigaltstack(%struct.TYPE_3__* %4, i32 0)
%31 = icmp ne i32 %30, -1
br i1 %31, label %40, label %32
32: ; preds = %26
%33 = load i64, i64* @errno
%34 = load i64, i64* @EINVAL
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENOMEM
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %36, %26
%41 = load i32, i32* @stderr
%42 = load i64, i64* @errno
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %42)
store i32 1, i32* %1
br label %45
44: ; preds = %36, %32
store i32 0, i32* %1
br label %45
45: ; preds = %44, %40, %22, %11
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
%struct.TYPE_3__ = type { i32, i64, i64 }
@errno = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"sigaction: Expected EINVAL, but got %d\0A\00"
@.str.1 = [42 x i8] c"sigprocmask: Expected EINVAL, but got %d\0A\00"
@ENOMEM = global i64 0
@.str.2 = [52 x i8] c"sigaltstack: Expected EINVAL or ENOMEM, but got %d\0A\00"
define i32 @main() {
%1 = alloca %struct.sigaction
%2 = alloca i32
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.sigaction* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.TYPE_3__* %3 to i8*
store i64 0, i64* @errno
%7 = call i32 @sigaction(i32 305419896, %struct.sigaction* %1, i32 0)
%8 = icmp eq i32 %7, -1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %42
16: ; preds = %0
store i64 0, i64* @errno
%17 = call i32 @sigprocmask(i32 305419896, i32* %2, i32 0)
%18 = icmp eq i32 %17, -1
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %19, %20
%22 = select i1 %18, i1 %21, i1 false
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %19)
br label %42
26: ; preds = %16
store i64 0, i64* @errno
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%29 = bitcast i64* %27 to i8*
store i32 305419896, i32* %28
%30 = call i32 @sigaltstack(%struct.TYPE_3__* %3, i32 0)
%31 = icmp eq i32 %30, -1
%32 = load i64, i64* @errno
br i1 %31, label %33, label %39
33: ; preds = %26
%34 = load i64, i64* @EINVAL
%35 = icmp eq i64 %32, %34
%36 = load i64, i64* @ENOMEM
%37 = icmp eq i64 %32, %36
%38 = select i1 %35, i1 true, i1 %37
br i1 %38, label %42, label %39
39: ; preds = %26, %33
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %32)
br label %42
42: ; preds = %33, %39, %23, %13
%43 = phi i32 [ 1, %13 ], [ 1, %23 ], [ 1, %39 ], [ 0, %33 ]
ret i32 %43
}