#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 i2c_finished0();
int i2c_finished1();
int I2C_wait(int mask) {
  if (mask & 0x01) {
    while (!i2c_finished0()) {
    }
    return i2c_finished0();
  };
  if (mask & 0x02) {
    while (!i2c_finished1()) {
    }
    return i2c_finished1();
  };
  return 0;
}


x86 assembly (clang, -O0):
<I2C_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     116f <I2C_wait+0x4f>
jmp    113f <I2C_wait+0x1f>
mov    $0x0,%al
call   1030 <i2c_finished0@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115b <I2C_wait+0x3b>
jmp    1160 <I2C_wait+0x40>
jmp    113f <I2C_wait+0x1f>
mov    $0x0,%al
call   1030 <i2c_finished0@plt>
mov    %eax,-0x4(%rbp)
jmp    11ba <I2C_wait+0x9a>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b3 <I2C_wait+0x93>
jmp    1183 <I2C_wait+0x63>
mov    $0x0,%al
call   1040 <i2c_finished1@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119f <I2C_wait+0x7f>
jmp    11a4 <I2C_wait+0x84>
jmp    1183 <I2C_wait+0x63>
mov    $0x0,%al
call   1040 <i2c_finished1@plt>
mov    %eax,-0x4(%rbp)
jmp    11ba <I2C_wait+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2C_wait>:
push   %rax
test   $0x1,%dil
jne    1140 <I2C_wait+0x20>
test   $0x2,%dil
jne    1160 <I2C_wait+0x40>
xor    %eax,%eax
pop    %rcx
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <i2c_finished0@plt>
test   %eax,%eax
je     1140 <I2C_wait+0x20>
xor    %eax,%eax
pop    %rcx
jmp    1030 <i2c_finished0@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <i2c_finished1@plt>
test   %eax,%eax
je     1160 <I2C_wait+0x40>
xor    %eax,%eax
pop    %rcx
jmp    1040 <i2c_finished1@plt>

LLVM IR (-O0):
define i32 @I2C_wait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
br label %8
8: ; preds = %12, %7
%9 = call i32 (...) @i2c_finished0()
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %13
12: ; preds = %8
br label %8
13: ; preds = %8
%14 = call i32 (...) @i2c_finished0()
store i32 %14, i32* %2
br label %28
15: ; preds = %1
%16 = load i32, i32* %3
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
br label %20
20: ; preds = %24, %19
%21 = call i32 (...) @i2c_finished1()
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %25
24: ; preds = %20
br label %20
25: ; preds = %20
%26 = call i32 (...) @i2c_finished1()
store i32 %26, i32* %2
br label %28
27: ; preds = %15
store i32 0, i32* %2
br label %28
28: ; preds = %27, %25, %13
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @I2C_wait(i32 %0) {
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %1, %4
%5 = tail call i32 (...) @i2c_finished0()
%6 = icmp eq i32 %5, 0
br i1 %6, label %4, label %7
7: ; preds = %4
%8 = tail call i32 (...) @i2c_finished0()
br label %17
9: ; preds = %1
%10 = and i32 %0, 2
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9, %12
%13 = tail call i32 (...) @i2c_finished1()
%14 = icmp eq i32 %13, 0
br i1 %14, label %12, label %15
15: ; preds = %12
%16 = tail call i32 (...) @i2c_finished1()
br label %17
17: ; preds = %9, %15, %7
%18 = phi i32 [ %8, %7 ], [ %16, %15 ], [ 0, %9 ]
ret i32 %18
}