#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 fci_i2c_transfer(void *, int, unsigned char, unsigned char *, unsigned char,
                     unsigned char *, unsigned char);
int /*<<< orphan*/ print_log(void *, char *, int, unsigned char, unsigned char);
signed int fci_i2c_read(void *handle, unsigned char chip, unsigned char addr,
                        unsigned char alen, unsigned char *data,
                        unsigned char len) {
  signed int ret;
  ret = fci_i2c_transfer(handle, 1, chip << 1, &addr, alen, data, len);
  if (ret != 0) {
    print_log(handle, "fci_i2c_read() result=%d, addr = %x, data=%x\n", ret,
              addr, *data);
    return ret;
  }
  return ret;
}


x86 assembly (clang, -O0):
<fci_i2c_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9b,%al
mov    %rdi,-0x10(%rbp)
mov    %sil,-0x11(%rbp)
mov    %dl,-0x12(%rbp)
mov    %cl,-0x13(%rbp)
mov    %r8,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
movzbl -0x11(%rbp),%eax
shl    $0x1,%eax
mov    %al,%dl
mov    -0x13(%rbp),%al
mov    -0x20(%rbp),%r9
mov    $0x1,%esi
lea    -0x12(%rbp),%rcx
movzbl %dl,%edx
movzbl %al,%r8d
movzbl -0x21(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <fci_i2c_transfer@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11a9 <fci_i2c_read+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x12(%rbp),%cl
mov    -0x20(%rbp),%rax
lea    0xe6e(%rip),%rsi
movzbl %cl,%ecx
movzbl (%rax),%r8d
call   1040 <print_log@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <fci_i2c_read+0x8f>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fci_i2c_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %ecx,%r8d
mov    %rdi,%rbx
mov    %dl,0xf(%rsp)
add    %sil,%sil
mov    %r9d,(%rsp)
movzbl %sil,%edx
lea    0xf(%rsp),%rcx
mov    $0x1,%esi
mov    %r14,%r9
call   1030 <fci_i2c_transfer@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1172 <fci_i2c_read+0x52>
movzbl 0xf(%rsp),%ecx
movzbl (%r14),%r8d
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <print_log@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"fci_i2c_read() result=%d, addr = %x, data=%x\0A\00"
define i32 @fci_i2c_read(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8* %4, i8 zeroext %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i8
%14 = alloca i32
store i8* %0, i8** %8
store i8 %1, i8* %9
store i8 %2, i8* %10
store i8 %3, i8* %11
store i8* %4, i8** %12
store i8 %5, i8* %13
%15 = load i8*, i8** %8
%16 = load i8, i8* %9
%17 = zext i8 %16 to i32
%18 = shl i32 %17, 1
%19 = trunc i32 %18 to i8
%20 = load i8, i8* %11
%21 = load i8*, i8** %12
%22 = load i8, i8* %13
%23 = call i32 @fci_i2c_transfer(i8* %15, i32 1, i8 zeroext %19, i8* %10, i8 zeroext %20, i8* %21, i8 zeroext %22)
store i32 %23, i32* %14
%24 = load i32, i32* %14
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %14
%29 = load i8, i8* %10
%30 = load i8*, i8** %12
%31 = load i8, i8* %30
%32 = call i32 @print_log(i8* %27, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %28, i8 zeroext %29, i8 zeroext %31)
%33 = load i32, i32* %14
store i32 %33, i32* %7
br label %36
34: ; preds = %6
%35 = load i32, i32* %14
store i32 %35, i32* %7
br label %36
36: ; preds = %34, %26
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
@.str = [46 x i8] c"fci_i2c_read() result=%d, addr = %x, data=%x\0A\00"
define i32 @fci_i2c_read(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8* %4, i8 zeroext %5) {
%7 = alloca i8
store i8 %2, i8* %7
%8 = shl i8 %1, 1
%9 = call i32 @fci_i2c_transfer(i8* %0, i32 1, i8 zeroext %8, i8* %7, i8 zeroext %3, i8* %4, i8 zeroext %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i8, i8* %7
%13 = load i8, i8* %4
%14 = call i32 @print_log(i8* %0, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %9, i8 zeroext %12, i8 zeroext %13)
br label %15
15: ; preds = %6, %11
ret i32 %9
}