#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 ece391_close(int);
int /*<<< orphan*/ ece391_fdputs(int, int /*<<< orphan*/ *);
int ece391_read(int, int /*<<< orphan*/ *, int);
int ece391_write(int, int /*<<< orphan*/ *, int);
int err_big_fd(void) {
  uint8_t buf[32];
  int fail = 0;
  if (-1 != ece391_read(1073741823, buf, 31)) {
    fail = 2;
    ece391_fdputs(1, (uint8_t *)"read fail\n");
  }
  if (-1 != ece391_write(1073741823, buf, 31)) {
    fail = 2;
    ece391_fdputs(1, (uint8_t *)"write fail\n");
  }
  if (-1 != ece391_close(1073741823)) {
    fail = 2;
    ece391_fdputs(1, (uint8_t *)"close fail\n");
  }
  if (fail) {
    ece391_fdputs(1, (uint8_t *)"err_big_fd: FAIL\n");
  } else {
    ece391_fdputs(1, (uint8_t *)"err_big_fd: PASS\n");
  }
  return fail;
}


x86 assembly (clang, -O0):
<err_big_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x84(%rbp)
lea    -0x80(%rbp),%rsi
mov    $0x3fffffff,%edi
mov    $0x1f,%edx
call   1050 <ece391_read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1192 <err_big_fd+0x52>
movl   $0x2,-0x84(%rbp)
mov    $0x1,%edi
lea    0xe73(%rip),%rsi
call   1040 <ece391_fdputs@plt>
lea    -0x80(%rbp),%rsi
mov    $0x3fffffff,%edi
mov    $0x1f,%edx
call   1060 <ece391_write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11cf <err_big_fd+0x8f>
movl   $0x2,-0x84(%rbp)
mov    $0x1,%edi
lea    0xe41(%rip),%rsi
call   1040 <ece391_fdputs@plt>
mov    $0x3fffffff,%edi
call   1030 <ece391_close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1203 <err_big_fd+0xc3>
movl   $0x2,-0x84(%rbp)
mov    $0x1,%edi
lea    0xe19(%rip),%rsi
call   1040 <ece391_fdputs@plt>
cmpl   $0x0,-0x84(%rbp)
je     1226 <err_big_fd+0xe6>
mov    $0x1,%edi
lea    0xe07(%rip),%rsi
call   1040 <ece391_fdputs@plt>
jmp    1237 <err_big_fd+0xf7>
mov    $0x1,%edi
lea    0xe03(%rip),%rsi
call   1040 <ece391_fdputs@plt>
mov    -0x84(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_big_fd>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %rsp,%rsi
mov    $0x3fffffff,%edi
mov    $0x1f,%edx
call   1050 <ece391_read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     117a <err_big_fd+0x3a>
lea    0xe97(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x2,%ebx
jmp    117c <err_big_fd+0x3c>
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    $0x3fffffff,%edi
mov    $0x1f,%edx
call   1060 <ece391_write@plt>
cmp    $0xffffffff,%eax
je     11b5 <err_big_fd+0x75>
lea    0xe71(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x3fffffff,%edi
call   1030 <ece391_close@plt>
cmp    $0xffffffff,%eax
jne    11c4 <err_big_fd+0x84>
jmp    11d5 <err_big_fd+0x95>
mov    $0x3fffffff,%edi
call   1030 <ece391_close@plt>
cmp    $0xffffffff,%eax
je     11f7 <err_big_fd+0xb7>
lea    0xe4c(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x2,%ebx
lea    0xe42(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0xffffffff,%ebp
lea    0xe34(%rip),%rax
lea    0xe1b(%rip),%rsi
cmove  %rax,%rsi
jmp    11e1 <err_big_fd+0xa1>

LLVM IR (-O0):
@.str = [11 x i8] c"read fail\0A\00"
@.str.1 = [12 x i8] c"write fail\0A\00"
@.str.2 = [12 x i8] c"close fail\0A\00"
@.str.3 = [18 x i8] c"err_big_fd: FAIL\0A\00"
@.str.4 = [18 x i8] c"err_big_fd: PASS\0A\00"
define i32 @err_big_fd() {
%1 = alloca [32 x i32]
%2 = alloca i32
store i32 0, i32* %2
%3 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 0
%4 = call i32 @ece391_read(i32 1073741823, i32* %3, i32 31)
%5 = icmp ne i32 -1, %4
br i1 %5, label %6, label %8
6: ; preds = %0
store i32 2, i32* %2
%7 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([11 x i8]* @.str to i32*))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 0
%10 = call i32 @ece391_write(i32 1073741823, i32* %9, i32 31)
%11 = icmp ne i32 -1, %10
br i1 %11, label %12, label %14
12: ; preds = %8
store i32 2, i32* %2
%13 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([12 x i8]* @.str.1 to i32*))
br label %14
14: ; preds = %12, %8
%15 = call i32 @ece391_close(i32 1073741823)
%16 = icmp ne i32 -1, %15
br i1 %16, label %17, label %19
17: ; preds = %14
store i32 2, i32* %2
%18 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([12 x i8]* @.str.2 to i32*))
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([18 x i8]* @.str.3 to i32*))
br label %26
24: ; preds = %19
%25 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([18 x i8]* @.str.4 to i32*))
br label %26
26: ; preds = %24, %22
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [11 x i8] c"read fail\0A\00"
@.str.1 = [12 x i8] c"write fail\0A\00"
@.str.2 = [12 x i8] c"close fail\0A\00"
@.str.3 = [18 x i8] c"err_big_fd: FAIL\0A\00"
@.str.4 = [18 x i8] c"err_big_fd: PASS\0A\00"
define i32 @err_big_fd() {
%1 = alloca [32 x i32]
%2 = bitcast [32 x i32]* %1 to i8*
%3 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 0
%4 = call i32 @ece391_read(i32 1073741823, i32* %3, i32 31)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([11 x i8]* @.str to i32*))
br label %8
8: ; preds = %6, %0
%9 = phi i32 [ 2, %6 ], [ 0, %0 ]
%10 = call i32 @ece391_write(i32 1073741823, i32* %3, i32 31)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @ece391_close(i32 1073741823)
%14 = icmp eq i32 %13, -1
br i1 %14, label %21, label %19
15: ; preds = %8
%16 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([12 x i8]* @.str.1 to i32*))
%17 = call i32 @ece391_close(i32 1073741823)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %15, %12
%20 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([12 x i8]* @.str.2 to i32*))
br label %23
21: ; preds = %12
%22 = select i1 %5, i32* bitcast ([18 x i8]* @.str.4 to i32*), i32* bitcast ([18 x i8]* @.str.3 to i32*)
br label %23
23: ; preds = %21, %19, %15
%24 = phi i32* [ bitcast ([18 x i8]* @.str.3 to i32*), %15 ], [ bitcast ([18 x i8]* @.str.3 to i32*), %19 ], [ %22, %21 ]
%25 = phi i32 [ 2, %15 ], [ 2, %19 ], [ %9, %21 ]
%26 = call i32 @ece391_fdputs(i32 1, i32* %24)
ret i32 %25
}