#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*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(void) {
  char buf[12];
  int fd;
  int len, ret, pos;
  fd = open("file1", O_RDONLY);
  len = read(fd, buf, 12);
  pos = 0;
  while (len > 0) {
    ret = write(1, buf + pos, len);
    len -= ret;
    pos += ret;
  }
  lseek(fd, 0, SEEK_SET);
  int i;
  for (i = 0; i < 12; i++) {
    printf("%d\n", buf[i] + '\0');
  }
  puts("\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11f0 <main+0x80>
lea    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11b2 <main+0x42>
mov    -0x14(%rbp),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xc,-0x24(%rbp)
jge    123d <main+0xcd>
movslq -0x24(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%eax
add    $0x0,%eax
lea    0xddf(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120a <main+0x9a>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r14d
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    11cd <main+0x5d>
mov    %eax,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
movslq %ebp,%rbp
lea    (%rsp,%rbp,1),%rsi
add    $0x4,%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1040 <write@plt>
add    %eax,%ebp
sub    %eax,%ebx
jg     11b0 <main+0x40>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
movsbl 0x4(%rsp),%esi
lea    0xe1a(%rip),%rbx
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0x5(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0x6(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0x7(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0x8(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0x9(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xa(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xd(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xe(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
lea    0xd7e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 12)
store i32 %12, i32* %4
store i32 0, i32* %6
br label %13
13: ; preds = %16, %0
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i32, i32* %4
%22 = call i32 @write(i32 1, i8* %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, %23
store i32 %25, i32* %4
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = add nsw i32 %27, %26
store i32 %28, i32* %6
br label %13
29: ; preds = %13
%30 = load i32, i32* %3
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @lseek(i32 %30, i32 0, i32 %31)
store i32 0, i32* %7
br label %33
33: ; preds = %45, %29
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 12
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = add nsw i32 %41, 0
%43 = trunc i32 %42 to i8
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %33
48: ; preds = %33
%49 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* %3
%51 = call i32 @close(i32 %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"file1\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @read(i32 %4, i8* %2, i32 12)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ 0, %0 ]
%9 = phi i32 [ %13, %7 ], [ %5, %0 ]
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %10
%12 = call i32 @write(i32 1, i8* %11, i32 %9)
%13 = sub nsw i32 %9, %12
%14 = add nsw i32 %12, %8
%15 = icmp sgt i32 %13, 0
br i1 %15, label %7, label %16
16: ; preds = %7, %0
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @lseek(i32 %4, i32 0, i32 %17)
%19 = load i8, i8* %2
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %19)
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 1
%22 = load i8, i8* %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %22)
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 2
%25 = load i8, i8* %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %25)
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 3
%28 = load i8, i8* %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %28)
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 4
%31 = load i8, i8* %30
%32 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %31)
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 5
%34 = load i8, i8* %33
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %34)
%36 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 6
%37 = load i8, i8* %36
%38 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %37)
%39 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 7
%40 = load i8, i8* %39
%41 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %40)
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 8
%43 = load i8, i8* %42
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %43)
%45 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 9
%46 = load i8, i8* %45
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %46)
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 10
%49 = load i8, i8* %48
%50 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %49)
%51 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 11
%52 = load i8, i8* %51
%53 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %52)
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%55 = tail call i32 @close(i32 %4)
ret i32 0
}