#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 LLI2C_input_data(int *);
int LLI2C_output_clock(int);
int LLI2C_output_data(int);
int LLI2C_set_data_for_input();
int LLI2C_set_data_for_output();
int receive_i2c_ack(int *p_ack) {
  int err;
  int bit;
  if (!p_ack)
    return 0x1000;
  err = LLI2C_set_data_for_input();
  if (err)
    return err;
  err = LLI2C_output_data(1);
  if (err)
    return err;
  err = LLI2C_output_clock(1);
  if (err)
    return err;
  err = LLI2C_input_data(&bit);
  if (err)
    return err;
  err = LLI2C_output_clock(0);
  if (err)
    return err;
  err = LLI2C_set_data_for_output();
  if (err)
    return err;
  *p_ack = !bit;
  return 0;
}


x86 assembly (clang, -O0):
<receive_i2c_ack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <receive_i2c_ack+0x23>
movl   $0x1000,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
mov    $0x0,%al
call   1040 <LLI2C_set_data_for_input@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1192 <receive_i2c_ack+0x42>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
mov    $0x1,%edi
call   1050 <LLI2C_output_data@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b4 <receive_i2c_ack+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
mov    $0x1,%edi
call   1070 <LLI2C_output_clock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <receive_i2c_ack+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
lea    -0x18(%rbp),%rdi
call   1060 <LLI2C_input_data@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f7 <receive_i2c_ack+0xa7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
xor    %edi,%edi
call   1070 <LLI2C_output_clock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1216 <receive_i2c_ack+0xc6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
mov    $0x0,%al
call   1030 <LLI2C_set_data_for_output@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1235 <receive_i2c_ack+0xe5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <receive_i2c_ack+0x100>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_i2c_ack>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11b8 <receive_i2c_ack+0x68>
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <LLI2C_set_data_for_input@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
mov    $0x1,%edi
call   1050 <LLI2C_output_data@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
mov    $0x1,%edi
call   1070 <LLI2C_output_clock@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
lea    0xc(%rsp),%rdi
call   1060 <LLI2C_input_data@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
xor    %edi,%edi
call   1070 <LLI2C_output_clock@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
xor    %eax,%eax
call   1030 <LLI2C_set_data_for_output@plt>
test   %eax,%eax
jne    11bd <receive_i2c_ack+0x6d>
xor    %eax,%eax
cmpl   $0x0,0xc(%rsp)
sete   %al
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    11bd <receive_i2c_ack+0x6d>
mov    $0x1000,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @receive_i2c_ack(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 4096, i32* %2
br label %51
9: ; preds = %1
%10 = call i32 (...) @LLI2C_set_data_for_input()
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %51
15: ; preds = %9
%16 = call i32 @LLI2C_output_data(i32 1)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %51
21: ; preds = %15
%22 = call i32 @LLI2C_output_clock(i32 1)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %51
27: ; preds = %21
%28 = call i32 @LLI2C_input_data(i32* %5)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %4
store i32 %32, i32* %2
br label %51
33: ; preds = %27
%34 = call i32 @LLI2C_output_clock(i32 0)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %51
39: ; preds = %33
%40 = call i32 (...) @LLI2C_set_data_for_output()
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i32, i32* %4
store i32 %44, i32* %2
br label %51
45: ; preds = %39
%46 = load i32, i32* %5
%47 = icmp ne i32 %46, 0
%48 = xor i1 %47, true
%49 = zext i1 %48 to i32
%50 = load i32*, i32** %3
store i32 %49, i32* %50
store i32 0, i32* %2
br label %51
51: ; preds = %45, %43, %37, %31, %25, %19, %13, %8
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @receive_i2c_ack(i32* writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i32* %0, null
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = tail call i32 (...) @LLI2C_set_data_for_input()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = tail call i32 @LLI2C_output_data(i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = tail call i32 @LLI2C_output_clock(i32 1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = call i32 @LLI2C_input_data(i32* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = call i32 @LLI2C_output_clock(i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = call i32 (...) @LLI2C_set_data_for_output()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
store i32 %26, i32* %0
br label %27
27: ; preds = %20, %17, %14, %11, %8, %5, %1, %23
%28 = phi i32 [ 0, %23 ], [ 4096, %1 ], [ %6, %5 ], [ %9, %8 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ], [ %21, %20 ]
ret i32 %28
}