#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 */

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int call_sys(int);
int /*<<< orphan*/ ece391_fdputs(int, int /*<<< orphan*/ *);
int err_syscall_num(void) {
  int fail = 0;
  if (-1 != call_sys(1073741823)) {
    ece391_fdputs(1, (uint8_t *)"syscall 0 fail\n");
    fail = 2;
  }
  if (-1 != call_sys(-1073741823)) {
    ece391_fdputs(1, (uint8_t *)"big num syscall fail\n");
    fail = 2;
  }
  if (-1 != call_sys(0)) {
    ece391_fdputs(1, (uint8_t *)"neg num syscall fail\n");
    fail = 2;
  }
  if (fail) {
    ece391_fdputs(1, (uint8_t *)"err_syscall_num: FAIL\n");
  } else {
    ece391_fdputs(1, (uint8_t *)"err_syscall_num: PASS\n");
  }
  return fail;
}


x86 assembly (clang, -O0):
<err_syscall_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3fffffff,%edi
call   1040 <call_sys@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1160 <err_syscall_num+0x40>
mov    $0x1,%edi
lea    0xeac(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
mov    $0xc0000001,%edi
call   1040 <call_sys@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1191 <err_syscall_num+0x71>
mov    $0x1,%edi
lea    0xe8b(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
xor    %edi,%edi
call   1040 <call_sys@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11bf <err_syscall_num+0x9f>
mov    $0x1,%edi
lea    0xe73(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11df <err_syscall_num+0xbf>
mov    $0x1,%edi
lea    0xe67(%rip),%rsi
call   1030 <ece391_fdputs@plt>
jmp    11f0 <err_syscall_num+0xd0>
mov    $0x1,%edi
lea    0xe68(%rip),%rsi
call   1030 <ece391_fdputs@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_syscall_num>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3fffffff,%edi
call   1040 <call_sys@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     114c <err_syscall_num+0x2c>
lea    0xec5(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    $0x2,%ebx
jmp    114e <err_syscall_num+0x2e>
xor    %ebx,%ebx
mov    $0xc0000001,%edi
call   1040 <call_sys@plt>
cmp    $0xffffffff,%eax
je     117c <err_syscall_num+0x5c>
lea    0xeac(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
xor    %edi,%edi
call   1040 <call_sys@plt>
cmp    $0xffffffff,%eax
jne    1188 <err_syscall_num+0x68>
jmp    1199 <err_syscall_num+0x79>
xor    %edi,%edi
call   1040 <call_sys@plt>
cmp    $0xffffffff,%eax
je     11b8 <err_syscall_num+0x98>
lea    0xe97(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    $0x2,%ebx
lea    0xe97(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0xffffffff,%ebp
lea    0xe91(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
jmp    11a5 <err_syscall_num+0x85>

LLVM IR (-O0):
@.str = [16 x i8] c"syscall 0 fail\0A\00"
@.str.1 = [22 x i8] c"big num syscall fail\0A\00"
@.str.2 = [22 x i8] c"neg num syscall fail\0A\00"
@.str.3 = [23 x i8] c"err_syscall_num: FAIL\0A\00"
@.str.4 = [23 x i8] c"err_syscall_num: PASS\0A\00"
define i32 @err_syscall_num() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @call_sys(i32 1073741823)
%3 = icmp ne i32 -1, %2
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([16 x i8]* @.str to i32*))
store i32 2, i32* %1
br label %6
6: ; preds = %4, %0
%7 = call i32 @call_sys(i32 -1073741823)
%8 = icmp ne i32 -1, %7
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([22 x i8]* @.str.1 to i32*))
store i32 2, i32* %1
br label %11
11: ; preds = %9, %6
%12 = call i32 @call_sys(i32 0)
%13 = icmp ne i32 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([22 x i8]* @.str.2 to i32*))
store i32 2, i32* %1
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([23 x i8]* @.str.3 to i32*))
br label %23
21: ; preds = %16
%22 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([23 x i8]* @.str.4 to i32*))
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [16 x i8] c"syscall 0 fail\0A\00"
@.str.1 = [22 x i8] c"big num syscall fail\0A\00"
@.str.2 = [22 x i8] c"neg num syscall fail\0A\00"
@.str.3 = [23 x i8] c"err_syscall_num: FAIL\0A\00"
@.str.4 = [23 x i8] c"err_syscall_num: PASS\0A\00"
define i32 @err_syscall_num() {
%1 = tail call i32 @call_sys(i32 1073741823)
%2 = icmp eq i32 %1, -1
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @ece391_fdputs(i32 1, i32* bitcast ([16 x i8]* @.str to i32*))
br label %5
5: ; preds = %3, %0
%6 = phi i32 [ 2, %3 ], [ 0, %0 ]
%7 = tail call i32 @call_sys(i32 -1073741823)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @call_sys(i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %18, label %16
12: ; preds = %5
%13 = tail call i32 @ece391_fdputs(i32 1, i32* bitcast ([22 x i8]* @.str.1 to i32*))
%14 = tail call i32 @call_sys(i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %12, %9
%17 = tail call i32 @ece391_fdputs(i32 1, i32* bitcast ([22 x i8]* @.str.2 to i32*))
br label %20
18: ; preds = %9
%19 = select i1 %2, i32* bitcast ([23 x i8]* @.str.4 to i32*), i32* bitcast ([23 x i8]* @.str.3 to i32*)
br label %20
20: ; preds = %18, %16, %12
%21 = phi i32* [ bitcast ([23 x i8]* @.str.3 to i32*), %12 ], [ bitcast ([23 x i8]* @.str.3 to i32*), %16 ], [ %19, %18 ]
%22 = phi i32 [ 2, %12 ], [ 2, %16 ], [ %6, %18 ]
%23 = tail call i32 @ece391_fdputs(i32 1, i32* %21)
ret i32 %22
}