#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 /*<<< orphan*/ ece391_fdputs(int, int /*<<< orphan*/ *);
int ece391_open(int /*<<< orphan*/ *);
int err_open(void) {
  int fail = 0;
  if (-1 != ece391_open((uint8_t *)"helloo")) {
    ece391_fdputs(1, (uint8_t *)"'helloo' fail\n");
    fail = 2;
  }
  if (-1 != ece391_open((uint8_t *)"shel")) {
    ece391_fdputs(1, (uint8_t *)"'shel' fail\n");
    fail = 2;
  }
  if (-1 != ece391_open((uint8_t *)"")) {
    ece391_fdputs(1, (uint8_t *)"empty string fail\n");
    fail = 2;
  }
  if (fail) {
    ece391_fdputs(1, (uint8_t *)"err_open: FAIL\n");
  } else {
    ece391_fdputs(1, (uint8_t *)"err_open: PASS\n");
  }
  return fail;
}


x86 assembly (clang, -O0):
<err_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1040 <ece391_open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1162 <err_open+0x42>
mov    $0x1,%edi
lea    0xeb1(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
lea    0xead(%rip),%rdi
call   1040 <ece391_open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1195 <err_open+0x75>
mov    $0x1,%edi
lea    0xe92(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1040 <ece391_open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11c8 <err_open+0xa8>
mov    $0x1,%edi
lea    0xe6c(%rip),%rsi
call   1030 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11e8 <err_open+0xc8>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1030 <ece391_fdputs@plt>
jmp    11f9 <err_open+0xd9>
mov    $0x1,%edi
lea    0xe57(%rip),%rsi
call   1030 <ece391_fdputs@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_open>:
push   %rbp
push   %rbx
push   %rax
lea    0xed6(%rip),%rdi
call   1040 <ece391_open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     114e <err_open+0x2e>
lea    0xeca(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    $0x2,%ebx
jmp    1150 <err_open+0x30>
xor    %ebx,%ebx
lea    0xebf(%rip),%rdi
call   1040 <ece391_open@plt>
cmp    $0xffffffff,%eax
je     1185 <err_open+0x65>
lea    0xeb3(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
lea    0xed1(%rip),%rdi
call   1040 <ece391_open@plt>
cmp    $0xffffffff,%eax
jne    1196 <err_open+0x76>
jmp    11a7 <err_open+0x87>
lea    0xebe(%rip),%rdi
call   1040 <ece391_open@plt>
cmp    $0xffffffff,%eax
je     11c6 <err_open+0xa6>
lea    0xe8b(%rip),%rsi
mov    $0x1,%edi
call   1030 <ece391_fdputs@plt>
mov    $0x2,%ebx
lea    0xe88(%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    0xe7b(%rip),%rax
lea    0xe64(%rip),%rsi
cmove  %rax,%rsi
jmp    11b3 <err_open+0x93>

LLVM IR (-O0):
@.str = [7 x i8] c"helloo\00"
@.str.1 = [15 x i8] c"'helloo' fail\0A\00"
@.str.2 = [5 x i8] c"shel\00"
@.str.3 = [13 x i8] c"'shel' fail\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [19 x i8] c"empty string fail\0A\00"
@.str.6 = [16 x i8] c"err_open: FAIL\0A\00"
@.str.7 = [16 x i8] c"err_open: PASS\0A\00"
define i32 @err_open() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @ece391_open(i32* bitcast ([7 x i8]* @.str to i32*))
%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 ([15 x i8]* @.str.1 to i32*))
store i32 2, i32* %1
br label %6
6: ; preds = %4, %0
%7 = call i32 @ece391_open(i32* bitcast ([5 x i8]* @.str.2 to i32*))
%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 ([13 x i8]* @.str.3 to i32*))
store i32 2, i32* %1
br label %11
11: ; preds = %9, %6
%12 = call i32 @ece391_open(i32* bitcast ([1 x i8]* @.str.4 to i32*))
%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 ([19 x i8]* @.str.5 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 ([16 x i8]* @.str.6 to i32*))
br label %23
21: ; preds = %16
%22 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([16 x i8]* @.str.7 to i32*))
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [7 x i8] c"helloo\00"
@.str.1 = [15 x i8] c"'helloo' fail\0A\00"
@.str.2 = [5 x i8] c"shel\00"
@.str.3 = [13 x i8] c"'shel' fail\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [19 x i8] c"empty string fail\0A\00"
@.str.6 = [16 x i8] c"err_open: FAIL\0A\00"
@.str.7 = [16 x i8] c"err_open: PASS\0A\00"
define i32 @err_open() {
%1 = tail call i32 @ece391_open(i32* bitcast ([7 x i8]* @.str to i32*))
%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 ([15 x i8]* @.str.1 to i32*))
br label %5
5: ; preds = %3, %0
%6 = phi i32 [ 2, %3 ], [ 0, %0 ]
%7 = tail call i32 @ece391_open(i32* bitcast ([5 x i8]* @.str.2 to i32*))
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @ece391_open(i32* bitcast ([1 x i8]* @.str.4 to i32*))
%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 ([13 x i8]* @.str.3 to i32*))
%14 = tail call i32 @ece391_open(i32* bitcast ([1 x i8]* @.str.4 to i32*))
%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 ([19 x i8]* @.str.5 to i32*))
br label %20
18: ; preds = %9
%19 = select i1 %2, i32* bitcast ([16 x i8]* @.str.7 to i32*), i32* bitcast ([16 x i8]* @.str.6 to i32*)
br label %20
20: ; preds = %18, %16, %12
%21 = phi i32* [ bitcast ([16 x i8]* @.str.6 to i32*), %12 ], [ bitcast ([16 x i8]* @.str.6 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
}