#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*/ i2cgetack();
char i2cgetbyte();
int /*<<< orphan*/ i2csendack();
int /*<<< orphan*/ i2csendbyte(char);
int /*<<< orphan*/ i2cstart();
int /*<<< orphan*/ i2cstop();
char I2C_Read(char Address, char *Data, char Num) {
  i2cstart();
  i2csendbyte(Address | 0x01);
  if (!i2cgetack()) {
    i2cstop();
    return (0);
  }
  while (Num--) {
    *Data = i2cgetbyte();
    Data++;
    if (Num > 0) {
      i2csendack();
    }
  }
  i2cstop();
  return (1);
}


x86 assembly (clang, -O0):
<I2C_Read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %dil,%cl
mov    %cl,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   1070 <i2cstart@plt>
movsbl -0x2(%rbp),%eax
or     $0x1,%eax
movsbl %al,%edi
call   1050 <i2csendbyte@plt>
mov    $0x0,%al
call   1030 <i2cgetack@plt>
cmp    $0x0,%eax
jne    11ad <I2C_Read+0x4d>
mov    $0x0,%al
call   1060 <i2cstop@plt>
movb   $0x0,-0x1(%rbp)
jmp    1204 <I2C_Read+0xa4>
jmp    11b2 <I2C_Read+0x52>
mov    -0x11(%rbp),%al
mov    %al,%cl
add    $0xff,%cl
mov    %cl,-0x11(%rbp)
cmp    $0x0,%al
je     11f9 <I2C_Read+0x99>
mov    $0x0,%al
call   1040 <i2cgetbyte@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jle    11f4 <I2C_Read+0x94>
mov    $0x0,%al
call   1080 <i2csendack@plt>
jmp    11b2 <I2C_Read+0x52>
mov    $0x0,%al
call   1060 <i2cstop@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<I2C_Read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <i2cstart@plt>
or     $0x1,%r15b
movsbl %r15b,%edi
call   1050 <i2csendbyte@plt>
xor    %eax,%eax
call   1030 <i2cgetack@plt>
test   %eax,%eax
je     11c1 <I2C_Read+0x61>
mov    $0x1,%r14b
test   %bpl,%bpl
je     11c1 <I2C_Read+0x61>
add    $0xff,%bpl
jmp    11aa <I2C_Read+0x4a>
nop
add    $0x1,%rbx
add    $0xff,%bpl
jae    11c1 <I2C_Read+0x61>
xor    %eax,%eax
call   1040 <i2cgetbyte@plt>
mov    %al,(%rbx)
test   %bpl,%bpl
jle    11a0 <I2C_Read+0x40>
xor    %eax,%eax
call   1080 <i2csendack@plt>
jmp    11a0 <I2C_Read+0x40>
xor    %eax,%eax
call   1060 <i2cstop@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @I2C_Read(i8 signext %0, i8* %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
store i8 %0, i8* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%8 = call i32 (...) @i2cstart()
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
%11 = or i32 %10, 1
%12 = trunc i32 %11 to i8
%13 = call i32 @i2csendbyte(i8 signext %12)
%14 = call i32 (...) @i2cgetack()
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = call i32 (...) @i2cstop()
store i8 0, i8* %4
br label %36
18: ; preds = %3
br label %19
19: ; preds = %33, %18
%20 = load i8, i8* %7
%21 = add i8 %20, -1
store i8 %21, i8* %7
%22 = icmp ne i8 %20, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = call signext i8 (...) @i2cgetbyte()
%25 = load i8*, i8** %6
store i8 %24, i8* %25
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
%28 = load i8, i8* %7
%29 = sext i8 %28 to i32
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 (...) @i2csendack()
br label %33
33: ; preds = %31, %23
br label %19
34: ; preds = %19
%35 = call i32 (...) @i2cstop()
store i8 1, i8* %4
br label %36
36: ; preds = %34, %16
%37 = load i8, i8* %4
ret i8 %37
}

LLVM IR (-O2):
define signext i8 @I2C_Read(i8 signext %0, i8* nocapture writeonly %1, i8 signext %2) {
%4 = tail call i32 (...) @i2cstart()
%5 = or i8 %0, 1
%6 = tail call i32 @i2csendbyte(i8 signext %5)
%7 = tail call i32 (...) @i2cgetack()
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = icmp eq i8 %2, 0
br i1 %10, label %22, label %11
11: ; preds = %9, %20
%12 = phi i8 [ %14, %20 ], [ %2, %9 ]
%13 = phi i8* [ %16, %20 ], [ %1, %9 ]
%14 = add i8 %12, -1
%15 = tail call signext i8 (...) @i2cgetbyte()
store i8 %15, i8* %13
%16 = getelementptr inbounds i8, i8* %13, i64 1
%17 = icmp sgt i8 %14, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = tail call i32 (...) @i2csendack()
br label %20
20: ; preds = %18, %11
%21 = icmp eq i8 %14, 0
br i1 %21, label %22, label %11
22: ; preds = %20, %9, %3
%23 = phi i8 [ 0, %3 ], [ 1, %9 ], [ 1, %20 ]
%24 = tail call i32 (...) @i2cstop()
ret i8 %23
}