#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 */
typedef int uint8_t;

/* Variables and functions */
int twi_master_clock_byte(int);
int twi_master_clock_byte_in(int *, int);
int twi_master_issue_startcondition();
int twi_master_issue_stopcondition();
bool twi_master_transfer(uint8_t address, uint8_t *data, uint8_t data_length,
                         bool issue_stop_condition) {
  bool transfer_succeeded = true;
  transfer_succeeded &= twi_master_issue_startcondition();
  transfer_succeeded &= twi_master_clock_byte(address);
  if (address & (0x01)) {
    while (data_length-- && transfer_succeeded) {
      if (data_length == 0) {
        transfer_succeeded &= twi_master_clock_byte_in(data, (bool)false);
      } else {
        transfer_succeeded &= twi_master_clock_byte_in(data, (bool)true);
      }
      data++;
    }
  } else {
    while (data_length-- && transfer_succeeded) {
      transfer_succeeded &= twi_master_clock_byte(*data);
      data++;
    }
  }
  if (issue_stop_condition || !transfer_succeeded) {
    transfer_succeeded &= twi_master_issue_stopcondition();
  }
  return transfer_succeeded;
}


x86 assembly (clang, -O0):
<twi_master_transfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <twi_master_issue_startcondition@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <twi_master_clock_byte@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1208 <twi_master_transfer+0xc8>
jmp    118b <twi_master_transfer+0x4b>
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     11ae <twi_master_transfer+0x6e>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11be <twi_master_transfer+0x7e>
jmp    1203 <twi_master_transfer+0xc3>
cmpl   $0x0,-0x14(%rbp)
jne    11de <twi_master_transfer+0x9e>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <twi_master_clock_byte_in@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f2 <twi_master_transfer+0xb2>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <twi_master_clock_byte_in@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    118b <twi_master_transfer+0x4b>
jmp    1267 <twi_master_transfer+0x127>
jmp    120d <twi_master_transfer+0xcd>
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1e(%rbp)
je     1230 <twi_master_transfer+0xf0>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1240 <twi_master_transfer+0x100>
jmp    1262 <twi_master_transfer+0x122>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <twi_master_clock_byte@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    120d <twi_master_transfer+0xcd>
jmp    1267 <twi_master_transfer+0x127>
cmpl   $0x0,-0x18(%rbp)
jne    127b <twi_master_transfer+0x13b>
cmpl   $0x0,-0x1c(%rbp)
jne    1288 <twi_master_transfer+0x148>
mov    $0x0,%al
call   1060 <twi_master_issue_stopcondition@plt>
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twi_master_transfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r13
mov    %edi,%r12d
xor    %eax,%eax
call   1040 <twi_master_issue_startcondition@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1050 <twi_master_clock_byte@plt>
and    %ebp,%eax
mov    %eax,%ebp
and    $0x1,%ebp
test   %r15d,%r15d
setne  %cl
and    %cl,%al
test   $0x1,%r12b
jne    11ae <twi_master_transfer+0x6e>
test   %al,%al
je     11de <twi_master_transfer+0x9e>
add    $0xffffffff,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,4),%edi
call   1050 <twi_master_clock_byte@plt>
mov    %eax,%ebp
and    $0x1,%ebp
cmp    %ebx,%r15d
je     11de <twi_master_transfer+0x9e>
add    $0x1,%rbx
test   %ebp,%ebp
jne    1190 <twi_master_transfer+0x50>
jmp    11de <twi_master_transfer+0x9e>
test   %al,%al
je     11de <twi_master_transfer+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%r15d
je     1204 <twi_master_transfer+0xc4>
mov    %r13,%rdi
mov    $0x1,%esi
call   1030 <twi_master_clock_byte_in@plt>
mov    %eax,%ebp
add    $0x4,%r13
and    $0x1,%ebp
jne    11c0 <twi_master_transfer+0x80>
test   %r14d,%r14d
jne    11ec <twi_master_transfer+0xac>
mov    $0x1,%eax
test   %ebp,%ebp
jne    11f5 <twi_master_transfer+0xb5>
xor    %eax,%eax
call   1060 <twi_master_issue_stopcondition@plt>
and    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <twi_master_clock_byte_in@plt>
mov    %eax,%ebp
and    $0x1,%ebp
test   %r14d,%r14d
je     11e3 <twi_master_transfer+0xa3>
jmp    11ec <twi_master_transfer+0xac>

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

LLVM IR (-O2):
define i32 @twi_master_transfer(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = tail call i32 (...) @twi_master_issue_startcondition()
%6 = and i32 %5, 1
%7 = tail call i32 @twi_master_clock_byte(i32 %0)
%8 = and i32 %6, %7
%9 = and i32 %0, 1
%10 = icmp eq i32 %9, 0
%11 = icmp ne i32 %2, 0
%12 = icmp ne i32 %8, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %10, label %15, label %14
14: ; preds = %4
br i1 %13, label %16, label %40
15: ; preds = %4
br i1 %13, label %29, label %40
16: ; preds = %14, %24
%17 = phi i32 [ %19, %24 ], [ %2, %14 ]
%18 = phi i32* [ %27, %24 ], [ %1, %14 ]
%19 = add nsw i32 %17, -1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @twi_master_clock_byte_in(i32* %18, i32 0)
%23 = and i32 %22, 1
br label %40
24: ; preds = %16
%25 = tail call i32 @twi_master_clock_byte_in(i32* %18, i32 1)
%26 = and i32 %25, 1
%27 = getelementptr inbounds i32, i32* %18, i64 1
%28 = icmp eq i32 %26, 0
br i1 %28, label %40, label %16
29: ; preds = %15, %29
%30 = phi i32* [ %36, %29 ], [ %1, %15 ]
%31 = phi i32 [ %32, %29 ], [ %2, %15 ]
%32 = add nsw i32 %31, -1
%33 = load i32, i32* %30
%34 = tail call i32 @twi_master_clock_byte(i32 %33)
%35 = and i32 %34, 1
%36 = getelementptr inbounds i32, i32* %30, i64 1
%37 = icmp ne i32 %32, 0
%38 = icmp ne i32 %35, 0
%39 = select i1 %37, i1 %38, i1 false
br i1 %39, label %29, label %40
40: ; preds = %24, %29, %21, %14, %15
%41 = phi i32 [ %8, %15 ], [ %8, %14 ], [ %23, %21 ], [ %35, %29 ], [ %26, %24 ]
%42 = icmp eq i32 %3, 0
%43 = icmp ne i32 %41, 0
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = tail call i32 (...) @twi_master_issue_stopcondition()
%47 = and i32 %46, %41
br label %48
48: ; preds = %40, %45
%49 = phi i32 [ 1, %40 ], [ %47, %45 ]
ret i32 %49
}