#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 send_i2c_data(int, unsigned char *);
int usleep(int);
int init_i2c_lcd(int fd, unsigned char *data) {
  unsigned char *ptr = &data[1];
  unsigned char ctrl_nibble = (1 << 3);
  unsigned char high_nibble = (0x03 << 4);
  *ptr = ctrl_nibble | high_nibble;
  int err = usleep(40);
  if (err == -1)
    return -1;
  for (int i = 0; i < 3; i++) {
    err = send_i2c_data(fd, data);
    if (err == -1)
      return -1;
    err = usleep(4100);
    if (err == -1)
      return -1;
  }
  high_nibble = (0x02 << 4);
  *ptr = ctrl_nibble | high_nibble;
  err = send_i2c_data(fd, data);
  if (err == -1)
    return -1;
  err = usleep(1600);
  if (err == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<init_i2c_lcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movb   $0x8,-0x19(%rbp)
movb   $0x30,-0x1a(%rbp)
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    $0x28,%edi
call   1040 <usleep@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1178 <init_i2c_lcd+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <init_i2c_lcd+0x129>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11e4 <init_i2c_lcd+0xc4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <send_i2c_data@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ae <init_i2c_lcd+0x8e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <init_i2c_lcd+0x129>
mov    $0x1004,%edi
call   1040 <usleep@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11d1 <init_i2c_lcd+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <init_i2c_lcd+0x129>
jmp    11d6 <init_i2c_lcd+0xb6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <init_i2c_lcd+0x5f>
movb   $0x20,-0x1a(%rbp)
movzbl -0x19(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <send_i2c_data@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    121f <init_i2c_lcd+0xff>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <init_i2c_lcd+0x129>
mov    $0x640,%edi
call   1040 <usleep@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1242 <init_i2c_lcd+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <init_i2c_lcd+0x129>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_i2c_lcd>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x38,0x1(%rsi)
mov    $0x28,%edi
call   1040 <usleep@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_i2c_data@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    $0x1004,%edi
call   1040 <usleep@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_i2c_data@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    $0x1004,%edi
call   1040 <usleep@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_i2c_data@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    $0x1004,%edi
call   1040 <usleep@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
movb   $0x28,0x1(%rbx)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <send_i2c_data@plt>
cmp    $0xffffffff,%eax
je     11ca <init_i2c_lcd+0xaa>
mov    $0x640,%edi
call   1040 <usleep@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
sete   %r14b
neg    %r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @init_i2c_lcd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %12, i8** %6
store i8 8, i8* %7
store i8 48, i8* %8
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = load i8, i8* %8
%16 = zext i8 %15 to i32
%17 = or i32 %14, %16
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %6
store i8 %18, i8* %19
%20 = call i32 @usleep(i32 40)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 -1, i32* %3
br label %64
24: ; preds = %2
store i32 0, i32* %10
br label %25
25: ; preds = %41, %24
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 3
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i8*, i8** %5
%31 = call i32 @send_i2c_data(i32 %29, i8* %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 -1, i32* %3
br label %64
35: ; preds = %28
%36 = call i32 @usleep(i32 4100)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 -1, i32* %3
br label %64
40: ; preds = %35
br label %41
41: ; preds = %40
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %25
44: ; preds = %25
store i8 32, i8* %8
%45 = load i8, i8* %7
%46 = zext i8 %45 to i32
%47 = load i8, i8* %8
%48 = zext i8 %47 to i32
%49 = or i32 %46, %48
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %6
store i8 %50, i8* %51
%52 = load i32, i32* %4
%53 = load i8*, i8** %5
%54 = call i32 @send_i2c_data(i32 %52, i8* %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %58
57: ; preds = %44
store i32 -1, i32* %3
br label %64
58: ; preds = %44
%59 = call i32 @usleep(i32 1600)
store i32 %59, i32* %9
%60 = load i32, i32* %9
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 -1, i32* %3
br label %64
63: ; preds = %58
store i32 0, i32* %3
br label %64
64: ; preds = %63, %62, %57, %39, %34, %23
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
define i32 @init_i2c_lcd(i32 %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 1
store i8 56, i8* %3
%4 = tail call i32 @usleep(i32 40)
%5 = icmp eq i32 %4, -1
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %31, label %24
9: ; preds = %24
%10 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = tail call i32 @usleep(i32 4100)
%14 = icmp eq i32 %13, -1
br i1 %14, label %31, label %15
15: ; preds = %12
%16 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = tail call i32 @usleep(i32 4100)
%20 = icmp eq i32 %19, -1
br i1 %20, label %31, label %21
21: ; preds = %18
store i8 40, i8* %3
%22 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%23 = icmp eq i32 %22, -1
br i1 %23, label %31, label %27
24: ; preds = %6
%25 = tail call i32 @usleep(i32 4100)
%26 = icmp eq i32 %25, -1
br i1 %26, label %31, label %9
27: ; preds = %21
%28 = tail call i32 @usleep(i32 1600)
%29 = icmp eq i32 %28, -1
%30 = sext i1 %29 to i32
br label %31
31: ; preds = %6, %24, %9, %12, %15, %18, %27, %21, %2
%32 = phi i32 [ -1, %2 ], [ -1, %21 ], [ %30, %27 ], [ -1, %18 ], [ -1, %15 ], [ -1, %12 ], [ -1, %9 ], [ -1, %24 ], [ -1, %6 ]
ret i32 %32
}