#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_RDWR;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
void main(void) {
  int file, cnt, i;
  char buf[32] = {0X00, 0x60, 0x55, 0X80, 0X40, 0X45};
  printf("******* Opening %s **********\n", "/dev/i2c_drv0");
  if ((file = open("/dev/i2c_drv0", O_RDWR)) < 0) {
    printf("Failed to open %s\n", "/dev/i2c_drv0");
    exit(1);
  }
  printf("\n******* Invoking Write in App *******\n");
  if (write(file, buf, 6) == 6) {
    sleep(1);
    printf("\n******* Writing EEPROM offset *******\n");
    for (i = 0; i < 32; i++)
      buf[i] = 0;
    printf("\n****** Invoking Read in App *******\n");
    if ((cnt = read(file, buf, 32)) <= 0) {
      printf("****** No Data recieved in App ******\n");
      return;
    }
    printf("\n****** Printing Recieved Buffer ******\n");
    for (i = 0; i < cnt; i++) {
      if (!(i % 15))
        printf("\n");
      printf("%x\t", buf[i]);
    }
  } else {
    printf("**** Failed to write the i2c bus ***\n");
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe88(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11e9 <main+0x89>
lea    0xe7c(%rip),%rdi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
jne    12fc <main+0x19c>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    1251 <main+0xf1>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1230 <main+0xd0>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jg     128f <main+0x12f>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1318 <main+0x1b8>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12f7 <main+0x197>
mov    -0xc(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12d2 <main+0x172>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xc(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12a4 <main+0x144>
jmp    130a <main+0x1aa>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe74(%rip),%rdi
lea    0xe8c(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12dc <main+0x15c>
mov    %eax,%ebx
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1050 <write@plt>
cmp    $0x6,%eax
jne    12aa <main+0x12a>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x20,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12bf <main+0x13f>
mov    %eax,%ebx
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%r13d
mov    $0x88888889,%r12d
lea    0xe01(%rip),%r15
lea    0xdd7(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    128a <main+0x10a>
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %rbx,%r13
je     12c6 <main+0x146>
mov    %ebx,%eax
imul   %r12,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%eax
add    %ebp,%eax
jne    1270 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1270 <main+0xf0>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
lea    0xd80(%rip),%r14
jmp    12c6 <main+0x146>
lea    0xe5e(%rip),%r14
mov    %r14,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xd6a(%rip),%rdi
lea    0xd55(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = <{ i8, i8, i8, i8, i8, i8, [26 x i8] }> <{ i8 0, i8 96, i8 85, i8 -128, i8 64, i8 69, [26 x i8] zeroinitializer }>
@.str = [31 x i8] c"******* Opening %s **********\0A\00"
@.str.1 = [14 x i8] c"/dev/i2c_drv0\00"
@O_RDWR = global i32 0
@.str.2 = [19 x i8] c"Failed to open %s\0A\00"
@.str.3 = [40 x i8] c"\0A******* Invoking Write in App *******\0A\00"
@.str.4 = [40 x i8] c"\0A******* Writing EEPROM offset *******\0A\00"
@.str.5 = [38 x i8] c"\0A****** Invoking Read in App *******\0A\00"
@.str.6 = [39 x i8] c"****** No Data recieved in App ******\0A\00"
@.str.7 = [41 x i8] c"\0A****** Printing Recieved Buffer ******\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [4 x i8] c"%x\09\00"
@.str.10 = [38 x i8] c"**** Failed to write the i2c bus ***\0A\00"
@.str.11 = [3 x i8] c"\0A\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = bitcast [32 x i8]* %4 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 %8, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%17 = call i32 @write(i32 %15, i8* %16, i32 6)
%18 = icmp eq i32 %17, 6
br i1 %18, label %19, label %63
19: ; preds = %13
%20 = call i32 @sleep(i32 1)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %22
22: ; preds = %29, %19
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 32
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %25
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %22
32: ; preds = %22
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* %1
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 32)
store i32 %36, i32* %2
%37 = icmp sle i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %67
40: ; preds = %32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %42
42: ; preds = %59, %40
%43 = load i32, i32* %3
%44 = load i32, i32* %2
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %62
46: ; preds = %42
%47 = load i32, i32* %3
%48 = srem i32 %47, 15
%49 = icmp ne i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %52
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 1
store i32 %61, i32* %3
br label %42
62: ; preds = %42
br label %65
63: ; preds = %13
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0))
br label %65
65: ; preds = %63, %62
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %67
67: ; preds = %65, %38
ret void
}

LLVM IR (-O2):
@__const.main.buf = <{ i8, i8, i8, i8, i8, i8, [26 x i8] }> <{ i8 0, i8 96, i8 85, i8 -128, i8 64, i8 69, [26 x i8] zeroinitializer }>
@.str = [31 x i8] c"******* Opening %s **********\0A\00"
@.str.1 = [14 x i8] c"/dev/i2c_drv0\00"
@O_RDWR = global i32 0
@.str.2 = [19 x i8] c"Failed to open %s\0A\00"
@.str.9 = [4 x i8] c"%x\09\00"
@str = [39 x i8] c"\0A******* Invoking Write in App *******\00"
@str.12 = [37 x i8] c"**** Failed to write the i2c bus ***\00"
@str.13 = [2 x i8] c"\0A\00"
@str.14 = [39 x i8] c"\0A******* Writing EEPROM offset *******\00"
@str.15 = [37 x i8] c"\0A****** Invoking Read in App *******\00"
@str.16 = [40 x i8] c"\0A****** Printing Recieved Buffer ******\00"
@str.17 = [38 x i8] c"****** No Data recieved in App ******\00"
define void @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%13 = call i32 @write(i32 %6, i8* %3, i32 6)
%14 = icmp eq i32 %13, 6
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.14, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.15, i64 0, i64 0))
%19 = call i32 @read(i32 %6, i8* %3, i32 32)
%20 = icmp slt i32 %19, 1
br i1 %20, label %40, label %21
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.16, i64 0, i64 0))
%23 = zext i32 %19 to i64
br label %24
24: ; preds = %21, %31
%25 = phi i64 [ 0, %21 ], [ %36, %31 ]
%26 = trunc i64 %25 to i32
%27 = urem i32 %26, 15
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @putchar(i32 10)
br label %31
31: ; preds = %29, %24
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %25
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %25, 1
%37 = icmp eq i64 %36, %23
br i1 %37, label %40, label %24
38: ; preds = %11
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.12, i64 0, i64 0))
br label %40
40: ; preds = %31, %38, %15
%41 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @str.17, i64 0, i64 0), %15 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0), %38 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0), %31 ]
%42 = tail call i32 @puts(i8* dereferenceable(1) %41)
ret void
}