#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;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_close(int);
int /*<<< orphan*/ ece391_fdputs(int, int /*<<< orphan*/ *);
int ece391_open(int /*<<< orphan*/ *);
int err_open_lots(void) {
  int32_t i, cnt = 0;
  for (i = 0; i < 7; i++) {
    if (-1 == ece391_open((uint8_t *)".")) {
      cnt++;
    }
  }
  for (i = 2; i < 8; i++) {
    ece391_close(i);
  }
  if (cnt == 1) {
    ece391_fdputs(1, (uint8_t *)"err_open_lots: PASS\n");
    return 0;
  } else {
    ece391_fdputs(1, (uint8_t *)"err_open_lots: FAIL\n");
    return 2;
  }
}


x86 assembly (clang, -O0):
<err_open_lots>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7,-0x8(%rbp)
jge    1187 <err_open_lots+0x57>
lea    0xea9(%rip),%rdi
call   1050 <ece391_open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1174 <err_open_lots+0x44>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <err_open_lots+0x49>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <err_open_lots+0x16>
movl   $0x2,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    11ae <err_open_lots+0x7e>
mov    -0x8(%rbp),%edi
call   1030 <ece391_close@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118e <err_open_lots+0x5e>
cmpl   $0x1,-0xc(%rbp)
jne    11d5 <err_open_lots+0xa5>
mov    $0x1,%edi
lea    0xe3e(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ed <err_open_lots+0xbd>
mov    $0x1,%edi
lea    0xe36(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_open_lots>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rbx
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
mov    %ecx,0x4(%rsp)
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %r15d,%r15d
cmp    $0xffffffff,%eax
sete   %r15b
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %r12d,%r12d
cmp    $0xffffffff,%eax
sete   %r12b
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %r13d,%r13d
cmp    $0xffffffff,%eax
sete   %r13b
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
sete   %r14b
mov    %rbx,%rdi
call   1050 <ece391_open@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
mov    $0x2,%edi
call   1030 <ece391_close@plt>
mov    $0x3,%edi
call   1030 <ece391_close@plt>
mov    $0x4,%edi
call   1030 <ece391_close@plt>
mov    $0x5,%edi
call   1030 <ece391_close@plt>
mov    $0x6,%edi
call   1030 <ece391_close@plt>
mov    $0x7,%edi
call   1030 <ece391_close@plt>
add    0x4(%rsp),%ebp
add    %r15d,%ebp
add    %r12d,%ebp
add    %r13d,%ebp
add    %r14d,%ebp
add    %ebx,%ebp
xor    %ebx,%ebx
cmp    $0x1,%ebp
setne  %bl
lea    0xde6(%rip),%rax
lea    0xdf4(%rip),%rsi
cmove  %rax,%rsi
add    %ebx,%ebx
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [21 x i8] c"err_open_lots: PASS\0A\00"
@.str.2 = [21 x i8] c"err_open_lots: FAIL\0A\00"
define i32 @err_open_lots() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %2
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 7
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
br label %13
13: ; preds = %10, %7
br label %14
14: ; preds = %13
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %4
17: ; preds = %4
store i32 2, i32* %2
br label %18
18: ; preds = %24, %17
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %2
%23 = call i32 @ece391_close(i32 %22)
br label %24
24: ; preds = %21
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %18
27: ; preds = %18
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([21 x i8]* @.str.1 to i32*))
store i32 0, i32* %1
br label %34
32: ; preds = %27
%33 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([21 x i8]* @.str.2 to i32*))
store i32 2, i32* %1
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [21 x i8] c"err_open_lots: PASS\0A\00"
@.str.2 = [21 x i8] c"err_open_lots: FAIL\0A\00"
define i32 @err_open_lots() {
%1 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%2 = icmp eq i32 %1, -1
%3 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%4 = icmp eq i32 %3, -1
%5 = zext i1 %4 to i32
%6 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%7 = icmp eq i32 %6, -1
%8 = zext i1 %7 to i32
%9 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%10 = icmp eq i32 %9, -1
%11 = zext i1 %10 to i32
%12 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
%15 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
%18 = tail call i32 @ece391_open(i32* bitcast ([2 x i8]* @.str to i32*))
%19 = icmp eq i32 %18, -1
%20 = zext i1 %19 to i32
%21 = tail call i32 @ece391_close(i32 2)
%22 = tail call i32 @ece391_close(i32 3)
%23 = tail call i32 @ece391_close(i32 4)
%24 = tail call i32 @ece391_close(i32 5)
%25 = tail call i32 @ece391_close(i32 6)
%26 = tail call i32 @ece391_close(i32 7)
%27 = zext i1 %2 to i32
%28 = add nuw nsw i32 %27, %5
%29 = add nuw nsw i32 %28, %8
%30 = add nuw nsw i32 %29, %11
%31 = add nuw nsw i32 %30, %14
%32 = add nuw nsw i32 %31, %17
%33 = add nuw nsw i32 %32, %20
%34 = icmp eq i32 %33, 1
%35 = select i1 %34, i32* bitcast ([21 x i8]* @.str.1 to i32*), i32* bitcast ([21 x i8]* @.str.2 to i32*)
%36 = select i1 %34, i32 0, i32 2
%37 = tail call i32 @ece391_fdputs(i32 1, i32* %35)
ret i32 %36
}