#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*/ debug_buffer_disk(int /*<<< orphan*/, int, int);
int open2(char *);
int /*<<< orphan*/ printf(char *, ...);
int read2(int, char *, int);
int /*<<< orphan*/ seek2(int, int);
int /*<<< orphan*/ truncate2(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 arq = open2("/arq");
  int size = 80;
  char buffer[size];
  int leu = read2(arq, buffer, size);
  int i = 0;
  for (i = leu; i >= 0; i = i - 5) {
    leu = read2(arq, buffer, size);
    printf("leu %d bytes de %d pedidos:\n %s\n\n\n", leu, size, buffer);
    seek2(arq, i);
    truncate2(arq);
  }
  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    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea8(%rip),%rdi
mov    %rdi,-0x48(%rbp)
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
mov    %al,-0x3d(%rbp)
call   1060 <printf@plt>
mov    -0x3c(%rbp),%edx
mov    $0x1,%esi
mov    %esi,-0x4c(%rbp)
mov    %edx,%edi
call   1070 <debug_buffer_disk@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3d(%rbp),%al
call   1060 <printf@plt>
mov    -0x4c(%rbp),%esi
mov    -0x3c(%rbp),%edi
mov    $0x2,%edx
call   1070 <debug_buffer_disk@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3d(%rbp),%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%edx
mov    %edx,%edi
mov    %edx,%esi
call   1070 <debug_buffer_disk@plt>
lea    0xe25(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,-0x14(%rbp)
movl   $0x50,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1050 <read2@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     1280 <main+0x120>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1050 <read2@plt>
mov    -0x38(%rbp),%rcx
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1040 <seek2@plt>
mov    -0x14(%rbp),%edi
call   1080 <truncate2@plt>
mov    -0x30(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x30(%rbp)
jmp    122b <main+0xcb>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edx,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1070 <debug_buffer_disk@plt>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1070 <debug_buffer_disk@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1070 <debug_buffer_disk@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%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   %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    0xe36(%rip),%rdi
call   1030 <open2@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x50,%edx
call   1060 <read2@plt>
test   %eax,%eax
js     122d <main+0xbd>
mov    %eax,%ebx
mov    %rsp,%r14
lea    0xe15(%rip),%r15
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1060 <read2@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x50,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <seek2@plt>
mov    %ebp,%edi
call   1090 <truncate2@plt>
lea    -0x5(%rbx),%eax
cmp    $0x4,%ebx
mov    %eax,%ebx
ja     11f0 <main+0x80>
lea    0xdf2(%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    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0A\0A\00"
@.str.1 = [5 x i8] c"/arq\00"
@.str.2 = [35 x i8] c"leu %d bytes de %d pedidos:\0A %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 i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%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 2)
%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 0, i32 0)
%18 = call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %6
store i32 80, i32* %7
%19 = load i32, i32* %7
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i32 @read2(i32 %23, i8* %22, i32 %24)
store i32 %25, i32* %10
store i32 0, i32* %11
%26 = load i32, i32* %10
store i32 %26, i32* %11
br label %27
27: ; preds = %42, %2
%28 = load i32, i32* %11
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 @read2(i32 %31, i8* %22, i32 %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35, i8* %22)
%37 = load i32, i32* %6
%38 = load i32, i32* %11
%39 = call i32 @seek2(i32 %37, i32 %38)
%40 = load i32, i32* %6
%41 = call i32 @truncate2(i32 %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, 5
store i32 %44, i32* %11
br label %27
45: ; preds = %27
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%51 = call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
store i32 0, i32* %3
%52 = load i8*, i8** %8
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"/arq\00"
@.str.2 = [35 x i8] c"leu %d bytes de %d pedidos:\0A %s\0A\0A\0A\00"
@str.7 = [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.7, 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.7, 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.7, i64 0, i64 0))
%8 = tail call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
%9 = tail call i32 @open2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = alloca [80 x i8]
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%12 = call i32 @read2(i32 %9, i8* %11, i32 80)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %2, %14
%15 = phi i32 [ %20, %14 ], [ %12, %2 ]
%16 = call i32 @read2(i32 %9, i8* %11, i32 80)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 80, i8* %11)
%18 = call i32 @seek2(i32 %9, i32 %15)
%19 = call i32 @truncate2(i32 %9)
%20 = add nsw i32 %15, -5
%21 = icmp ugt i32 %15, 4
br i1 %21, label %14, label %22
22: ; preds = %14, %2
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%24 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 0)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%26 = call i32 @debug_buffer_disk(i32 0, i32 1, i32 2)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%28 = call i32 @debug_buffer_disk(i32 0, i32 0, i32 0)
ret i32 0
}