#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*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int write(int, unsigned char *, int);
main() {
  unsigned char init_data1[3] = {0x00, 0xa5, 0x00};
  unsigned char init_data2[3] = {0x00, 0xa4, 0x11};
  unsigned char init_data[189] = {
      0x00, 0xa5, 0x00, 0x00, 0xa4, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x7f, 0xff, 0xff,
      0x7f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x7f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x00, 0xc8, 0x00,
      0x00, 0xc3, 0x01, 0x00, 0xc6, 0x01, 0x00, 0xc2, 0x00, 0x00, 0xc1, 0x00,
      0x3f, 0xc4, 0xd5, 0x00, 0xc9, 0x78, 0x00, 0xac, 0x00, 0xff, 0xad, 0x86,
      0x00, 0x00, 0x00, 0xff, 0xad, 0x84, 0x00, 0x00, 0x17, 0xff, 0xad, 0x80,
      0x00, 0x54, 0x54, 0xff, 0xad, 0x87, 0x00, 0x54, 0x54, 0xff, 0xad, 0x81,
      0x00, 0x12, 0x12, 0xff, 0xad, 0x82, 0x00, 0x14, 0x14, 0xff, 0xad, 0x83,
      0x00, 0x00, 0x00, 0xff, 0xad, 0x86, 0x00, 0x00, 0x01, 0xff, 0xad, 0x86,
      0x00, 0x00, 0x00, 0xff, 0xad, 0x85, 0x00, 0x00, 0x00, 0xff, 0xad, 0x85,
      0x00, 0x01, 0x01, 0xff, 0xad, 0x86, 0x00, 0x00, 0x01, 0xff, 0xad, 0x86,
      0x00, 0x00, 0x00, 0xff, 0xad, 0x85, 0x00, 0x1f, 0xff, 0xff, 0xad, 0x86,
      0x00, 0x00, 0x01, 0xff, 0xad, 0x86, 0x00, 0x00, 0x00, 0x00, 0xD2, 0x75,
      0x00, 0xD0, 0x7F, 0x00, 0xD1, 0x50, 0x00, 0xD2, 0x50,
  };
  int fd;
  fd = open("/dev/i2c-0", O_RDWR);
  if (fd < 0) {
    printf("open i2c bus fail!\n");
  } else {
    printf("fd = %d\n", fd);
  }
  int ret;
  ret = ioctl(fd, I2C_SLAVE, 0x73);
  while (ret < 0) {
    printf("ioctl set i2c slave fail, set again!\n");
    usleep(500000);
    ioctl(fd, I2C_SLAVE, 0x73);
  }
  printf("ioctl ret = %d\n", ret);
  int k;
  for (k = 0; k < 30; k++) {
    ret = write(fd, (init_data + 3 * k), 3);
    if (ret > 0) {
      printf("write %d bytes OK,init_data1 command send OK!\n", ret);
    } else {
      printf("init_data1 command send fail!\n");
    }
    usleep(500);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe77(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe6f(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xe66(%rip),%ax
mov    %ax,-0xa(%rbp)
mov    0xe5e(%rip),%al
mov    %al,-0x8(%rbp)
lea    -0xd0(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0xbd,%edx
call   1070 <memcpy@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xefb(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0x0,-0xd4(%rbp)
jge    11fd <main+0x8d>
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1211 <main+0xa1>
mov    -0xd4(%rbp),%esi
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xd4(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    $0x73,%edx
call   1050 <ioctl@plt>
mov    %eax,-0xd8(%rbp)
cmpl   $0x0,-0xd8(%rbp)
jge    1273 <main+0x103>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    -0xd4(%rbp),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    $0x73,%edx
call   1050 <ioctl@plt>
jmp    1230 <main+0xc0>
mov    -0xd8(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xdc(%rbp)
cmpl   $0x1e,-0xdc(%rbp)
jge    1319 <main+0x1a9>
mov    -0xd4(%rbp),%edi
lea    -0xd0(%rbp),%rsi
imul   $0x3,-0xdc(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x3,%edx
call   1030 <write@plt>
mov    %eax,-0xd8(%rbp)
cmpl   $0x0,-0xd8(%rbp)
jle    12ed <main+0x17d>
mov    -0xd8(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fb <main+0x18b>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1f4,%edi
call   1090 <usleep@plt>
mov    -0xdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
jmp    1291 <main+0x121>
mov    -0xd4(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc0,%rsp
lea    0xe6a(%rip),%rsi
mov    %rsp,%rdi
mov    $0xbd,%edx
call   1080 <memcpy@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xf0a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r12d
test   %eax,%eax
js     11d2 <main+0x52>
lea    0xf02(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11de <main+0x5e>
lea    0xf7a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dfb(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    $0x73,%edx
call   1060 <ioctl@plt>
test   %eax,%eax
js     1279 <main+0xf9>
lea    0xecd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xecd(%rip),%r14
lea    0xef5(%rip),%r15
xor    %ebx,%ebx
jmp    123c <main+0xbc>
nop
mov    %r15,%rdi
call   1030 <puts@plt>
mov    $0x1f4,%edi
call   10a0 <usleep@plt>
add    $0x3,%rbx
cmp    $0x5a,%rbx
je     125f <main+0xdf>
lea    (%rsp,%rbx,1),%rsi
mov    %r12d,%edi
mov    $0x3,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    1220 <main+0xa0>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1228 <main+0xa8>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    $0x73,%edx
call   1060 <ioctl@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    0x0(%rbp),%esi
mov    %r12d,%edi
mov    $0x73,%edx
call   1060 <ioctl@plt>
jmp    12b0 <main+0x130>

LLVM IR (-O0):
@__const.main.init_data1 = [3 x i8] c"\00\A5\00"
@__const.main.init_data2 = [3 x i8] c"\00\A4\11"
@__const.main.init_data = [189 x i8] c"\00\A5\00\00\A4\11\00\00\00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\7F\FF\FF\7F\FF\FF\7F\FF\FF\00\00\00\00\00\00\00\00\00\7F\FF\FF\00\00\00\7F\FF\FF\00\C8\00\00\C3\01\00\C6\01\00\C2\00\00\C1\00?\C4\D5\00\C9x\00\AC\00\FF\AD\86\00\00\00\FF\AD\84\00\00\17\FF\AD\80\00TT\FF\AD\87\00TT\FF\AD\81\00\12\12\FF\AD\82\00\14\14\FF\AD\83\00\00\00\FF\AD\86\00\00\01\FF\AD\86\00\00\00\FF\AD\85\00\00\00\FF\AD\85\00\01\01\FF\AD\86\00\00\01\FF\AD\86\00\00\00\FF\AD\85\00\1F\FF\FF\AD\86\00\00\01\FF\AD\86\00\00\00\00\D2u\00\D0\7F\00\D1P\00\D2P"
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"open i2c bus fail!\0A\00"
@.str.2 = [9 x i8] c"fd = %d\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [38 x i8] c"ioctl set i2c slave fail, set again!\0A\00"
@.str.4 = [16 x i8] c"ioctl ret = %d\0A\00"
@.str.5 = [47 x i8] c"write %d bytes OK,init_data1 command send OK!\0A\00"
@.str.6 = [31 x i8] c"init_data1 command send fail!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = alloca [3 x i8]
%4 = alloca [189 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [3 x i8]* %2 to i8*
%9 = bitcast [3 x i8]* %3 to i8*
%10 = bitcast [189 x i8]* %4 to i8*
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %0
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %15
%21 = load i32, i32* %5
%22 = load i32, i32* @I2C_SLAVE
%23 = call i32 @ioctl(i32 %21, i32 %22, i32 115)
store i32 %23, i32* %6
br label %24
24: ; preds = %27, %20
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @usleep(i32 500000)
%30 = load i32, i32* %5
%31 = load i32, i32* @I2C_SLAVE
%32 = call i32 @ioctl(i32 %30, i32 %31, i32 115)
br label %24
33: ; preds = %24
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %34)
store i32 0, i32* %7
br label %36
36: ; preds = %56, %33
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 30
br i1 %38, label %39, label %59
39: ; preds = %36
%40 = load i32, i32* %5
%41 = getelementptr inbounds [189 x i8], [189 x i8]* %4, i64 0, i64 0
%42 = load i32, i32* %7
%43 = mul nsw i32 3, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = call i32 @write(i32 %40, i8* %45, i32 3)
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %39
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %54
52: ; preds = %39
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = call i32 @usleep(i32 500)
br label %56
56: ; preds = %54
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %36
59: ; preds = %36
%60 = load i32, i32* %5
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@__const.main.init_data = [189 x i8] c"\00\A5\00\00\A4\11\00\00\00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\7F\FF\FF\7F\FF\FF\7F\FF\FF\00\00\00\00\00\00\00\00\00\7F\FF\FF\00\00\00\7F\FF\FF\00\C8\00\00\C3\01\00\C6\01\00\C2\00\00\C1\00?\C4\D5\00\C9x\00\AC\00\FF\AD\86\00\00\00\FF\AD\84\00\00\17\FF\AD\80\00TT\FF\AD\87\00TT\FF\AD\81\00\12\12\FF\AD\82\00\14\14\FF\AD\83\00\00\00\FF\AD\86\00\00\01\FF\AD\86\00\00\00\FF\AD\85\00\00\00\FF\AD\85\00\01\01\FF\AD\86\00\00\01\FF\AD\86\00\00\00\FF\AD\85\00\1F\FF\FF\AD\86\00\00\01\FF\AD\86\00\00\00\00\D2u\00\D0\7F\00\D1P\00\D2P"
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.2 = [9 x i8] c"fd = %d\0A\00"
@I2C_SLAVE = global i32 0
@.str.4 = [16 x i8] c"ioctl ret = %d\0A\00"
@.str.5 = [47 x i8] c"write %d bytes OK,init_data1 command send OK!\0A\00"
@str = [30 x i8] c"init_data1 command send fail!\00"
@str.7 = [37 x i8] c"ioctl set i2c slave fail, set again!\00"
@str.8 = [19 x i8] c"open i2c bus fail!\00"
define i32 @main() {
%1 = alloca [189 x i8]
%2 = getelementptr inbounds [189 x i8], [189 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %4)
br label %10
10: ; preds = %8, %6
%11 = load i32, i32* @I2C_SLAVE
%12 = tail call i32 @ioctl(i32 %4, i32 %11, i32 115)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0))
%16 = tail call i32 @usleep(i32 500000)
%17 = load i32, i32* @I2C_SLAVE
%18 = tail call i32 @ioctl(i32 %4, i32 %17, i32 115)
br label %19
19: ; preds = %19, %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0))
%21 = tail call i32 @usleep(i32 500000)
%22 = load i32, i32* @I2C_SLAVE
%23 = tail call i32 @ioctl(i32 %4, i32 %22, i32 115)
br label %19
24: ; preds = %10
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %26
26: ; preds = %24, %36
%27 = phi i64 [ 0, %24 ], [ %38, %36 ]
%28 = mul nuw nsw i64 %27, 3
%29 = getelementptr inbounds [189 x i8], [189 x i8]* %1, i64 0, i64 %28
%30 = call i32 @write(i32 %4, i8* %29, i32 3)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %36
34: ; preds = %26
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %32
%37 = tail call i32 @usleep(i32 500)
%38 = add nuw nsw i64 %27, 1
%39 = icmp eq i64 %38, 30
br i1 %39, label %40, label %26
40: ; preds = %36
%41 = tail call i32 @close(i32 %4)
ret i32 0
}