#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 /*<<< orphan*/ liic_delay_(unsigned int);
scalar_t__ liic_scl_(unsigned int, int);
scalar_t__ liic_sda_(unsigned int, int);
int recv(unsigned num, int ack) {
  int c = 0;
  for (int i = 0; i < 9; ++i) {
    liic_scl_(num, 0);
    if (i == 8)
      liic_sda_(num, ack);
    else
      liic_sda_(num, 1);
    liic_delay_(num);
    while (liic_scl_(num, 1) == 0)
      ;
    liic_delay_(num);
    if (i != 8) {
      c <<= 1;
      if (liic_sda_(num, 1) != 0)
        c |= 1;
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x9,-0x10(%rbp)
jge    11fe <recv+0xce>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <liic_scl_@plt>
cmpl   $0x8,-0x10(%rbp)
jne    117a <recv+0x4a>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <liic_sda_@plt>
jmp    1187 <recv+0x57>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <liic_sda_@plt>
mov    -0x4(%rbp),%edi
call   1040 <liic_delay_@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <liic_scl_@plt>
cmp    $0x0,%rax
jne    11ab <recv+0x7b>
jmp    118f <recv+0x5f>
mov    -0x4(%rbp),%edi
call   1040 <liic_delay_@plt>
cmpl   $0x8,-0x10(%rbp)
je     11eb <recv+0xbb>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <liic_sda_@plt>
cmp    $0x0,%rax
je     11e6 <recv+0xb6>
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <recv+0xbb>
jmp    11f0 <recv+0xc0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <recv+0x1c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <liic_scl_@plt>
cmp    $0x8,%ebx
mov    $0x1,%esi
cmove  %r14d,%esi
mov    %ebp,%edi
call   1050 <liic_sda_@plt>
mov    %ebp,%edi
call   1040 <liic_delay_@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <liic_scl_@plt>
test   %rax,%rax
je     1180 <recv+0x50>
mov    %ebp,%edi
call   1040 <liic_delay_@plt>
cmp    $0x8,%ebx
je     11ba <recv+0x8a>
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <liic_sda_@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%r15,2),%r15d
add    $0x1,%ebx
jmp    1150 <recv+0x20>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @recv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %46, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 9
br i1 %9, label %10, label %49
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call i64 @liic_scl_(i32 %11, i32 0)
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 8
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i64 @liic_sda_(i32 %16, i32 %17)
br label %22
19: ; preds = %10
%20 = load i32, i32* %3
%21 = call i64 @liic_sda_(i32 %20, i32 1)
br label %22
22: ; preds = %19, %15
%23 = load i32, i32* %3
%24 = call i32 @liic_delay_(i32 %23)
br label %25
25: ; preds = %29, %22
%26 = load i32, i32* %3
%27 = call i64 @liic_scl_(i32 %26, i32 1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
br label %25
30: ; preds = %25
%31 = load i32, i32* %3
%32 = call i32 @liic_delay_(i32 %31)
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 8
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load i32, i32* %5
%37 = shl i32 %36, 1
store i32 %37, i32* %5
%38 = load i32, i32* %3
%39 = call i64 @liic_sda_(i32 %38, i32 1)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %5
%43 = or i32 %42, 1
store i32 %43, i32* %5
br label %44
44: ; preds = %41, %35
br label %45
45: ; preds = %44, %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %7
49: ; preds = %7
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
define i32 @recv(i32 %0, i32 %1) {
br label %4
3: ; preds = %15
ret i32 %6
4: ; preds = %17, %2
%5 = phi i32 [ 0, %2 ], [ %23, %17 ]
%6 = phi i32 [ 0, %2 ], [ %22, %17 ]
%7 = tail call i64 @liic_scl_(i32 %0, i32 0)
%8 = icmp eq i32 %5, 8
%9 = select i1 %8, i32 %1, i32 1
%10 = tail call i64 @liic_sda_(i32 %0, i32 %9)
%11 = tail call i32 @liic_delay_(i32 %0)
br label %12
12: ; preds = %12, %4
%13 = tail call i64 @liic_scl_(i32 %0, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %12, label %15
15: ; preds = %12
%16 = tail call i32 @liic_delay_(i32 %0)
br i1 %8, label %3, label %17
17: ; preds = %15
%18 = shl i32 %6, 1
%19 = tail call i64 @liic_sda_(i32 %0, i32 1)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
%22 = or i32 %18, %21
%23 = add nuw nsw i32 %5, 1
br label %4
}