#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 read_whitney(int, unsigned long *);
int write_whitney(int, int);
int LLI2C_input_data(int *p_state) {
  int err;
  unsigned long gpio;
  if (!p_state)
    return 0x1000;
  err = write_whitney(0x5014, 0x0100);
  if (err)
    return err;
  err = write_whitney(0x5014, 0x0000);
  if (err)
    return err;
  err = read_whitney(0x5014, &gpio);
  if (err)
    return err;
  *p_state = (gpio & 0x1000) ? 1 : 0;
  return 0;
}


x86 assembly (clang, -O0):
<LLI2C_input_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <LLI2C_input_data+0x23>
movl   $0x1000,-0x4(%rbp)
jmp    11da <LLI2C_input_data+0xba>
mov    $0x5014,%edi
mov    $0x100,%esi
call   1030 <write_whitney@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116a <LLI2C_input_data+0x4a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <LLI2C_input_data+0xba>
mov    $0x5014,%edi
xor    %esi,%esi
call   1030 <write_whitney@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <LLI2C_input_data+0x6e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <LLI2C_input_data+0xba>
mov    $0x5014,%edi
lea    -0x20(%rbp),%rsi
call   1040 <read_whitney@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b4 <LLI2C_input_data+0x94>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <LLI2C_input_data+0xba>
mov    -0x20(%rbp),%rdx
and    $0x1000,%rdx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%rdx
cmovne %eax,%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):
<LLI2C_input_data>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1173 <LLI2C_input_data+0x53>
mov    %rdi,%rbx
mov    $0x5014,%edi
mov    $0x100,%esi
call   1030 <write_whitney@plt>
test   %eax,%eax
jne    1178 <LLI2C_input_data+0x58>
mov    $0x5014,%edi
xor    %esi,%esi
call   1030 <write_whitney@plt>
test   %eax,%eax
jne    1178 <LLI2C_input_data+0x58>
lea    0x8(%rsp),%rsi
mov    $0x5014,%edi
call   1040 <read_whitney@plt>
test   %eax,%eax
jne    1178 <LLI2C_input_data+0x58>
mov    0x8(%rsp),%eax
shr    $0xc,%eax
and    $0x1,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    1178 <LLI2C_input_data+0x58>
mov    $0x1000,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @LLI2C_input_data(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
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 %34
9: ; preds = %1
%10 = call i32 @write_whitney(i32 20500, i32 256)
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 %34
15: ; preds = %9
%16 = call i32 @write_whitney(i32 20500, i32 0)
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 %34
21: ; preds = %15
%22 = call i32 @read_whitney(i32 20500, i64* %5)
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 %34
27: ; preds = %21
%28 = load i64, i64* %5
%29 = and i64 %28, 4096
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 0
%33 = load i32*, i32** %3
store i32 %32, i32* %33
store i32 0, i32* %2
br label %34
34: ; preds = %27, %25, %19, %13, %8
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @LLI2C_input_data(i32* writeonly %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = icmp eq i32* %0, null
br i1 %4, label %19, label %5
5: ; preds = %1
%6 = tail call i32 @write_whitney(i32 20500, i32 256)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = tail call i32 @write_whitney(i32 20500, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = call i32 @read_whitney(i32 20500, i64* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
%17 = lshr i32 %16, 12
%18 = and i32 %17, 1
store i32 %18, i32* %0
br label %19
19: ; preds = %11, %8, %5, %1, %14
%20 = phi i32 [ 0, %14 ], [ 4096, %1 ], [ %6, %5 ], [ %9, %8 ], [ %12, %11 ]
ret i32 %20
}