#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, 0x50, 0xAA, 0X55, 0X33, 0XAA};
  printf("******* Opening %s **********\n", "/dev/i2c_dmy0");
  if ((file = open("/dev/i2c_dmy0", O_RDWR)) < 0) {
    printf("Failed to open %s\n", "/dev/i2c_dmy0");
    exit(1);
  }
  printf("\n******* Invoking Write in App *******\n");
  if (write(file, buf, 6) == 6) {
    sleep(1);
    printf("\n******* Writing EEPROM offset *******\n");
    write(file, buf, 2);
    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    130d <main+0x1ad>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    1262 <main+0x102>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1241 <main+0xe1>
lea    0xe47(%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     12a0 <main+0x140>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1329 <main+0x1c9>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1308 <main+0x1a8>
mov    -0xc(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12e3 <main+0x183>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xc(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12b5 <main+0x155>
jmp    131b <main+0x1bb>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2e(%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     12ec <main+0x16c>
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    12ba <main+0x13a>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <write@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x20,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12cf <main+0x14f>
mov    %eax,%ebx
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%r13d
mov    $0x88888889,%r12d
lea    0xdef(%rip),%r15
lea    0xdc5(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    129a <main+0x11a>
xchg   %ax,%ax
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     12d6 <main+0x156>
mov    %ebx,%eax
imul   %r12,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%eax
add    %ebp,%eax
jne    1280 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1280 <main+0x100>
lea    0xdca(%rip),%rdi
call   1040 <puts@plt>
lea    0xd70(%rip),%r14
jmp    12d6 <main+0x156>
lea    0xe4e(%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    0xd5a(%rip),%rdi
lea    0xd45(%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 80, i8 -86, i8 85, i8 51, i8 -86, [26 x i8] zeroinitializer }>
@.str = [31 x i8] c"******* Opening %s **********\0A\00"
@.str.1 = [14 x i8] c"/dev/i2c_dmy0\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 %66
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))
%22 = load i32, i32* %1
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%24 = call i32 @write(i32 %22, i8* %23, i32 2)
store i32 0, i32* %3
br label %25
25: ; preds = %32, %19
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 32
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %28
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %25
35: ; preds = %25
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32, i32* %1
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 32)
store i32 %39, i32* %2
%40 = icmp sle i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %70
43: ; preds = %35
%44 = 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 %45
45: ; preds = %62, %43
%46 = load i32, i32* %3
%47 = load i32, i32* %2
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %45
%50 = load i32, i32* %3
%51 = srem i32 %50, 15
%52 = icmp ne i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %55
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %45
65: ; preds = %45
br label %68
66: ; preds = %13
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0))
br label %68
68: ; preds = %66, %65
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %70
70: ; preds = %68, %41
ret void
}

LLVM IR (-O2):
@__const.main.buf = <{ i8, i8, i8, i8, i8, i8, [26 x i8] }> <{ i8 0, i8 80, i8 -86, i8 85, i8 51, i8 -86, [26 x i8] zeroinitializer }>
@.str = [31 x i8] c"******* Opening %s **********\0A\00"
@.str.1 = [14 x i8] c"/dev/i2c_dmy0\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 %39
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 = call i32 @write(i32 %6, i8* %3, i32 2)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.15, i64 0, i64 0))
%20 = call i32 @read(i32 %6, i8* %3, i32 32)
%21 = icmp slt i32 %20, 1
br i1 %21, label %41, label %22
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.16, i64 0, i64 0))
%24 = zext i32 %20 to i64
br label %25
25: ; preds = %22, %32
%26 = phi i64 [ 0, %22 ], [ %37, %32 ]
%27 = trunc i64 %26 to i32
%28 = urem i32 %27, 15
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = tail call i32 @putchar(i32 10)
br label %32
32: ; preds = %30, %25
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %26
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %26, 1
%38 = icmp eq i64 %37, %24
br i1 %38, label %41, label %25
39: ; preds = %11
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.12, i64 0, i64 0))
br label %41
41: ; preds = %32, %39, %15
%42 = 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), %39 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0), %32 ]
%43 = tail call i32 @puts(i8* dereferenceable(1) %42)
ret void
}