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

/* Variables and functions */
int /*<<< orphan*/ close2(int);
int /*<<< orphan*/ closedir2(int);
int /*<<< orphan*/ debug_buffer_disk(int /*<<< orphan*/, int, int);
int open2(char *);
int opendir2(char *);
int /*<<< orphan*/ printf(char *, ...);
int read2(int, char *, int);
int main(int argc, const char *argv[]) {
  printf("\n\n");
  debug_buffer_disk(0, 1, 0);
  printf("\n\n");
  debug_buffer_disk(0, 1, 2);
  printf("\n\n");
  debug_buffer_disk(0, 0, 0);
  int sub = opendir2("/sub/");
  int file = open2("file");
  int arq = open2("/arq");
  int arq2 = open2("/sub/arq2");
  int size = 80;
  char buffer[size];
  int leu = read2(arq, buffer, size);
  printf("leu %d bytes de %d pedidos: %s\n\n\n", leu, size, buffer);
  size = 10;
  leu = read2(arq, buffer, size);
  printf("leu %d bytes de %d pedidos: %s\n\n\n", leu, size, buffer);
  leu = read2(arq2, buffer, size);
  printf("leu %d bytes de %d pedidos: %s\n\n\n", leu, size, buffer);
  size = 80;
  leu = read2(arq2, buffer, size);
  printf("leu %d bytes de %d pedidos: %s\n\n\n", leu, size, buffer);
  close2(arq);
  close2(arq2);
  close2(sub);
  closedir2(sub);
  closedir2(file);
  close2(file);
  printf("\n\n");
  debug_buffer_disk(0, 1, 0);
  printf("\n\n");
  debug_buffer_disk(0, 1, 2);
  printf("\n\n");
  debug_buffer_disk(0, 0, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeac(%rip),%rdi
mov    %rdi,-0x58(%rbp)
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
mov    %al,-0x4d(%rbp)
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edx
mov    $0x1,%esi
mov    %esi,-0x5c(%rbp)
mov    %edx,%edi
call   1070 <debug_buffer_disk@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4d(%rbp),%al
call   1050 <printf@plt>
mov    -0x5c(%rbp),%esi
mov    -0x4c(%rbp),%edi
mov    $0x2,%edx
call   1070 <debug_buffer_disk@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4d(%rbp),%al
call   1050 <printf@plt>
mov    -0x4c(%rbp),%edx
mov    %edx,%edi
mov    %edx,%esi
call   1070 <debug_buffer_disk@plt>
lea    0xe15(%rip),%rdi
call   1080 <opendir2@plt>
mov    %eax,-0x14(%rbp)
lea    0xe0c(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,-0x18(%rbp)
lea    0xe02(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdf8(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,-0x20(%rbp)
movl   $0x50,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x48(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1040 <read2@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rsi
movl   $0xa,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1040 <read2@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1040 <read2@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rsi
movl   $0x50,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1040 <read2@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close2@plt>
mov    -0x20(%rbp),%edi
call   1060 <close2@plt>
mov    -0x14(%rbp),%edi
call   1060 <close2@plt>
mov    -0x14(%rbp),%edi
call   1090 <closedir2@plt>
mov    -0x18(%rbp),%edi
call   1090 <closedir2@plt>
mov    -0x18(%rbp),%edi
call   1060 <close2@plt>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edx,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1070 <debug_buffer_disk@plt>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1070 <debug_buffer_disk@plt>
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1070 <debug_buffer_disk@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xea5(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <debug_buffer_disk@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <debug_buffer_disk@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <debug_buffer_disk@plt>
lea    0xe22(%rip),%rdi
call   1090 <opendir2@plt>
mov    %eax,%r12d
lea    0xe19(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,%r15d
lea    0xe0f(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,%r13d
lea    0xe05(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x50,%edx
call   1050 <read2@plt>
lea    0xdee(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x50,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1050 <read2@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0xa,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1050 <read2@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0xa,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x50,%edx
call   1050 <read2@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x50,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13d,%edi
call   1070 <close2@plt>
mov    %ebx,%edi
call   1070 <close2@plt>
mov    %r12d,%edi
call   1070 <close2@plt>
mov    %r12d,%edi
call   10a0 <closedir2@plt>
mov    %r15d,%edi
call   10a0 <closedir2@plt>
mov    %r15d,%edi
call   1070 <close2@plt>
lea    0xd5a(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <debug_buffer_disk@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <debug_buffer_disk@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <debug_buffer_disk@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0A\0A\00"
@.str.1 = [6 x i8] c"/sub/\00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [5 x i8] c"/arq\00"
@.str.4 = [10 x i8] c"/sub/arq2\00"
@.str.5 = [34 x i8] c"leu %d bytes de %d pedidos: %s\0A\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
%20 = call i32 @opendir2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %20, i32* %6
%21 = call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 %21, i32* %7
%22 = call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 %22, i32* %8
%23 = call i32 @open2(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %23, i32* %9
store i32 80, i32* %10
%24 = load i32, i32* %10
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %11
%27 = alloca i8, i64 %25
store i64 %25, i64* %12
%28 = load i32, i32* %8
%29 = load i32, i32* %10
%30 = call i32 @read2(i32 %28, i8* %27, i32 %29)
store i32 %30, i32* %13
%31 = load i32, i32* %13
%32 = load i32, i32* %10
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32, i8* %27)
store i32 10, i32* %10
%34 = load i32, i32* %8
%35 = load i32, i32* %10
%36 = call i32 @read2(i32 %34, i8* %27, i32 %35)
store i32 %36, i32* %13
%37 = load i32, i32* %13
%38 = load i32, i32* %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %38, i8* %27)
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = call i32 @read2(i32 %40, i8* %27, i32 %41)
store i32 %42, i32* %13
%43 = load i32, i32* %13
%44 = load i32, i32* %10
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %44, i8* %27)
store i32 80, i32* %10
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = call i32 @read2(i32 %46, i8* %27, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = load i32, i32* %10
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50, i8* %27)
%52 = load i32, i32* %8
%53 = call i32 @close2(i32 %52)
%54 = load i32, i32* %9
%55 = call i32 @close2(i32 %54)
%56 = load i32, i32* %6
%57 = call i32 @close2(i32 %56)
%58 = load i32, i32* %6
%59 = call i32 @closedir2(i32 %58)
%60 = load i32, i32* %7
%61 = call i32 @closedir2(i32 %60)
%62 = load i32, i32* %7
%63 = call i32 @close2(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%65 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%67 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%69 = call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
store i32 0, i32* %3
%70 = load i8*, i8** %11
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"/sub/\00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [5 x i8] c"/arq\00"
@.str.4 = [10 x i8] c"/sub/arq2\00"
@.str.5 = [34 x i8] c"leu %d bytes de %d pedidos: %s\0A\0A\0A\00"
@str.10 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%4 = tail call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
%9 = tail call i32 @opendir2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @open2(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%13 = alloca [80 x i8]
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%15 = call i32 @read2(i32 %11, i8* %14, i32 80)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %15, i32 80, i8* %14)
%17 = call i32 @read2(i32 %11, i8* %14, i32 10)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %17, i32 10, i8* %14)
%19 = call i32 @read2(i32 %12, i8* %14, i32 10)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %19, i32 10, i8* %14)
%21 = call i32 @read2(i32 %12, i8* %14, i32 80)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 80, i8* %14)
%23 = call i32 @close2(i32 %11)
%24 = call i32 @close2(i32 %12)
%25 = call i32 @close2(i32 %9)
%26 = call i32 @closedir2(i32 %9)
%27 = call i32 @closedir2(i32 %10)
%28 = call i32 @close2(i32 %10)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%30 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%32 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%34 = call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
ret i32 0
}