#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*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int main() {
  char buf[100];
  char test;
  int file;
  file = open("./chota2.bin", O_RDONLY);
  if (file == -1) {
    printf("error open\n");
    exit(1);
  }
  while (read(file, buf, 36) == 36) {
    printf("%hhx %hhx %hhx %hhx %hhx %hhx\n", buf[1], buf[2], buf[3], buf[4],
           buf[5], buf[6]);
  }
  puts("read end");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0xffffffff,-0x78(%rbp)
jne    119c <main+0x4c>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11a1 <main+0x51>
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x24,%edx
call   1050 <read@plt>
cmp    $0x24,%eax
jne    11eb <main+0x9b>
movsbl -0x6f(%rbp),%esi
movsbl -0x6e(%rbp),%edx
movsbl -0x6d(%rbp),%ecx
movsbl -0x6c(%rbp),%r8d
movsbl -0x6b(%rbp),%r9d
movsbl -0x6a(%rbp),%eax
lea    0xe3d(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a1 <main+0x51>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11fc <main+0xac>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x24,%edx
call   1050 <read@plt>
cmp    $0x24,%eax
jne    11e1 <main+0x91>
lea    0xe74(%rip),%r14
lea    0x10(%rsp),%r15
xchg   %ax,%ax
movsbl 0x11(%rsp),%esi
movsbl 0x12(%rsp),%edx
movsbl 0x13(%rsp),%ecx
movsbl 0x14(%rsp),%r8d
movsbl 0x15(%rsp),%r9d
movsbl 0x16(%rsp),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x24,%edx
call   1050 <read@plt>
cmp    $0x24,%eax
je     11a0 <main+0x50>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"./chota2.bin\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"error open\0A\00"
@.str.2 = [31 x i8] c"%hhx %hhx %hhx %hhx %hhx %hhx\0A\00"
@.str.3 = [9 x i8] c"read end\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %18, %12
%14 = load i32, i32* %4
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 36)
%17 = icmp eq i32 %16, 36
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 6
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %24, i32 %27, i32 %30, i32 %33, i32 %36)
br label %13
38: ; preds = %13
%39 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"./chota2.bin\00"
@O_RDONLY = global i32 0
@.str.2 = [31 x i8] c"%hhx %hhx %hhx %hhx %hhx %hhx\0A\00"
@.str.3 = [9 x i8] c"read end\00"
@str = [11 x i8] c"error open\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 36)
%8 = icmp eq i32 %7, 36
br i1 %8, label %9, label %35
9: ; preds = %6
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 5
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 6
br label %19
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9, %19
%20 = load i8, i8* %10
%21 = sext i8 %20 to i32
%22 = load i8, i8* %11
%23 = sext i8 %22 to i32
%24 = load i8, i8* %12
%25 = sext i8 %24 to i32
%26 = load i8, i8* %13
%27 = sext i8 %26 to i32
%28 = load i8, i8* %14
%29 = sext i8 %28 to i32
%30 = load i8, i8* %15
%31 = sext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
%33 = call i32 @read(i32 %4, i8* %2, i32 36)
%34 = icmp eq i32 %33, 36
br i1 %34, label %19, label %35
35: ; preds = %19, %6
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}