#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 send_data(int fd, unsigned char *data, bool is_character) {
  unsigned char *ptr = &data[1];
  unsigned char ctrl_nibble = (1 << 3);
  if (is_character)
    ctrl_nibble |= (1 << 0);
  else
    ctrl_nibble &= ~(1 << 0);
  unsigned char high_nibble = (data[1] & 0xF0);
  unsigned char low_nibble = ((data[1] & 0x0F) << 4);
  *ptr = ctrl_nibble | high_nibble;
  int err = send_i2c_data(fd, data);
  if (err == -1)
    return -1;
  err = usleep(1);
  if (err == -1)
    return -1;
  *ptr = ctrl_nibble | low_nibble;
  err = send_i2c_data(fd, data);
  if (err == -1)
    return -1;
  err = usleep(1);
  if (err == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movb   $0x8,-0x21(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115b <send_data+0x3b>
movzbl -0x21(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x21(%rbp)
jmp    1165 <send_data+0x45>
movzbl -0x21(%rbp),%eax
and    $0xfffffffe,%eax
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf0,%eax
mov    %al,-0x22(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf,%eax
shl    $0x4,%eax
mov    %al,-0x23(%rbp)
movzbl -0x21(%rbp),%eax
movzbl -0x22(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <send_i2c_data@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11bd <send_data+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <send_data+0x121>
mov    $0x1,%edi
call   1040 <usleep@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11e0 <send_data+0xc0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <send_data+0x121>
movzbl -0x21(%rbp),%eax
movzbl -0x23(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <send_i2c_data@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1217 <send_data+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <send_data+0x121>
mov    $0x1,%edi
call   1040 <usleep@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    123a <send_data+0x11a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <send_data+0x121>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %edi,%r14d
cmp    $0x1,%edx
mov    $0x9,%bl
sbb    $0x0,%bl
mov    0x1(%rsi),%r12b
mov    %r12d,%eax
and    $0xf0,%al
or     %bl,%al
mov    %al,0x1(%rsi)
call   1030 <send_i2c_data@plt>
mov    $0xffffffff,%r15d
cmp    $0xffffffff,%eax
je     1195 <send_data+0x75>
mov    $0x1,%edi
call   1040 <usleep@plt>
cmp    $0xffffffff,%eax
je     1195 <send_data+0x75>
shl    $0x4,%r12b
or     %bl,%r12b
mov    %r12b,0x1(%rbp)
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <send_i2c_data@plt>
cmp    $0xffffffff,%eax
je     1195 <send_data+0x75>
mov    $0x1,%edi
call   1040 <usleep@plt>
xor    %r15d,%r15d
cmp    $0xffffffff,%eax
sete   %r15b
neg    %r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @send_data(i32 %0, i8* %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i8 8, i8 9
%7 = load i8, i8* %4
%8 = and i8 %7, -16
%9 = shl i8 %7, 4
%10 = or i8 %8, %6
store i8 %10, i8* %4
%11 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %24, label %13
13: ; preds = %3
%14 = tail call i32 @usleep(i32 1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = or i8 %9, %6
store i8 %17, i8* %4
%18 = tail call i32 @send_i2c_data(i32 %0, i8* %1)
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = tail call i32 @usleep(i32 1)
%22 = icmp eq i32 %21, -1
%23 = sext i1 %22 to i32
br label %24
24: ; preds = %20, %16, %13, %3
%25 = phi i32 [ -1, %3 ], [ -1, %13 ], [ -1, %16 ], [ %23, %20 ]
ret i32 %25
}