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

/* Variables and functions */
scalar_t__ do_one_file(char *, char *);
int /*<<< orphan*/ ece391_fdputs(int, char *);
scalar_t__ ece391_getargs(char *, int);
int ece391_open(char *);
int ece391_read(int, char *, int);
int main() {
  int32_t fd, cnt;
  uint8_t buf[33];
  uint8_t search[1024];
  if (0 != ece391_getargs(search, 1024)) {
    ece391_fdputs(1, (uint8_t *)"could not read argument\n");
    return 3;
  }
  if (-1 == (fd = ece391_open((uint8_t *)"."))) {
    ece391_fdputs(1, (uint8_t *)"directory open failed\n");
    return 2;
  }
  while (0 != (cnt = ece391_read(fd, buf, 33 - 1))) {
    if (-1 == cnt) {
      ece391_fdputs(1, (uint8_t *)"directory entry read failed\n");
      return 3;
    }
    if ('.' == buf[0])
      continue;
    buf[cnt] = '\0';
    if (0 != do_one_file((char *)search, (char *)buf))
      return 3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1050 <ece391_getargs@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     119e <main+0x4e>
mov    $0x1,%edi
lea    0xe73(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x3,-0x4(%rbp)
jmp    127e <main+0x12e>
lea    0xe74(%rip),%rdi
call   1070 <ece391_open@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11d9 <main+0x89>
mov    $0x1,%edi
lea    0xe53(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
jmp    127e <main+0x12e>
jmp    11de <main+0x8e>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1060 <ece391_read@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     1277 <main+0x127>
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    1229 <main+0xd9>
mov    $0x1,%edi
lea    0xe1a(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x3,-0x4(%rbp)
jmp    127e <main+0x12e>
movsbl -0x30(%rbp),%ecx
mov    $0x2e,%eax
cmp    %ecx,%eax
jne    123f <main+0xef>
jmp    11de <main+0x8e>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x430(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <do_one_file@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1272 <main+0x122>
movl   $0x3,-0x4(%rbp)
jmp    127e <main+0x12e>
jmp    11de <main+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x438,%rsp
lea    0x30(%rsp),%rdi
mov    $0x400,%esi
call   1050 <ece391_getargs@plt>
mov    $0x3,%r14d
test   %rax,%rax
je     1199 <main+0x49>
lea    0xe82(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    %r14d,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe79(%rip),%rdi
call   1070 <ece391_open@plt>
cmp    $0xffffffff,%eax
je     11fc <main+0xac>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0x30(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1060 <ece391_read@plt>
cmp    $0xffffffff,%eax
je     120e <main+0xbe>
test   %eax,%eax
je     121a <main+0xca>
cmpb   $0x2e,(%rsp)
je     11c0 <main+0x70>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <do_one_file@plt>
test   %rax,%rax
je     11c0 <main+0x70>
mov    $0x3,%r14d
jmp    1188 <main+0x38>
mov    $0x2,%r14d
lea    0xe12(%rip),%rsi
jmp    117e <main+0x2e>
lea    0xe1d(%rip),%rsi
jmp    117e <main+0x2e>
mov    %eax,%r14d
jmp    1188 <main+0x38>

LLVM IR (-O0):
@.str = [25 x i8] c"could not read argument\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [23 x i8] c"directory open failed\0A\00"
@.str.3 = [29 x i8] c"directory entry read failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [33 x i8]
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i64 @ece391_getargs(i8* %6, i32 1024)
%8 = icmp ne i64 0, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %1
br label %44
11: ; preds = %0
%12 = call i32 @ece391_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %12, i32* %2
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %44
16: ; preds = %11
br label %17
17: ; preds = %42, %32, %16
%18 = load i32, i32* %2
%19 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%20 = call i32 @ece391_read(i32 %18, i8* %19, i32 32)
store i32 %20, i32* %3
%21 = icmp ne i32 0, %20
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = load i32, i32* %3
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @ece391_fdputs(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %1
br label %44
27: ; preds = %22
%28 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 46, %30
br i1 %31, label %32, label %33
32: ; preds = %27
br label %17
33: ; preds = %27
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%38 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%39 = call i64 @do_one_file(i8* %37, i8* %38)
%40 = icmp ne i64 0, %39
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 3, i32* %1
br label %44
42: ; preds = %33
br label %17
43: ; preds = %17
store i32 0, i32* %1
br label %44
44: ; preds = %43, %41, %25, %14, %9
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [25 x i8] c"could not read argument\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [23 x i8] c"directory open failed\0A\00"
@.str.3 = [29 x i8] c"directory entry read failed\0A\00"
define i32 @main() {
%1 = alloca [33 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i64 @ece391_getargs(i8* %4, i32 1024)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %0
%8 = call i32 @ece391_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %21, label %10
10: ; preds = %7, %15
%11 = call i32 @ece391_read(i32 %8, i8* %3, i32 32)
switch i32 %11, label %12 [
i32 0, label %25
i32 -1, label %21
]
12: ; preds = %10
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %16
15: ; preds = %12, %16
br label %10
16: ; preds = %12
%17 = sext i32 %11 to i64
%18 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i64 @do_one_file(i8* %4, i8* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %15, label %25
21: ; preds = %10, %7, %0
%22 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %10 ]
%23 = phi i32 [ 3, %0 ], [ 2, %7 ], [ 3, %10 ]
%24 = call i32 @ece391_fdputs(i32 1, i8* %22)
br label %25
25: ; preds = %10, %16, %21
%26 = phi i32 [ %23, %21 ], [ %11, %10 ], [ 3, %16 ]
ret i32 %26
}