#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint16_t;

/* Variables and functions */
int EFAULT;
int i2c_smbus_read_word_data(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int i2c_read_word(int file, uint8_t reg_addr, uint16_t *data) {
  int res;
  if (NULL == data) {
    return -EFAULT;
  }
  if ((res = i2c_smbus_read_word_data(file, reg_addr)) < 0) {
    if ((res = i2c_smbus_read_word_data(file, reg_addr)) < 0) {
      perror("i2c_smbus_read_word_data");
      return res;
    }
  }
  *data = res;
  return 0;
}


x86 assembly (clang, -O0):
<i2c_read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1151 <i2c_read_word+0x31>
xor    %eax,%eax
mov    0x2eb1(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <i2c_read_word+0x8b>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <i2c_smbus_read_word_data@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    119b <i2c_read_word+0x7b>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <i2c_smbus_read_word_data@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1196 <i2c_read_word+0x76>
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <i2c_read_word+0x8b>
jmp    119b <i2c_read_word+0x7b>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read_word>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     1157 <i2c_read_word+0x37>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r15d
call   1030 <i2c_smbus_read_word_data@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1151 <i2c_read_word+0x31>
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <i2c_smbus_read_word_data@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116f <i2c_read_word+0x4f>
mov    %ebp,(%rbx)
xor    %ebp,%ebp
jmp    1162 <i2c_read_word+0x42>
mov    0x2e9a(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
call   1040 <perror@plt>
jmp    1162 <i2c_read_word+0x42>

LLVM IR (-O0):
@EFAULT = global i32 0
@.str = [25 x i8] c"i2c_smbus_read_word_data\00"
define i32 @i2c_read_word(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* null, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @EFAULT
%13 = sub nsw i32 0, %12
store i32 %13, i32* %4
br label %31
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @i2c_smbus_read_word_data(i32 %15, i32 %16)
store i32 %17, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @i2c_smbus_read_word_data(i32 %20, i32 %21)
store i32 %22, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %31
27: ; preds = %19
br label %28
28: ; preds = %27, %14
%29 = load i32, i32* %8
%30 = load i32*, i32** %7
store i32 %29, i32* %30
store i32 0, i32* %4
br label %31
31: ; preds = %28, %24, %11
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@EFAULT = global i32 0
@.str = [25 x i8] c"i2c_smbus_read_word_data\00"
define i32 @i2c_read_word(i32 %0, i32 %1, i32* writeonly %2) {
%4 = icmp eq i32* %2, null
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = load i32, i32* @EFAULT
%7 = sub nsw i32 0, %6
br label %18
8: ; preds = %3
%9 = tail call i32 @i2c_smbus_read_word_data(i32 %0, i32 %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = tail call i32 @i2c_smbus_read_word_data(i32 %0, i32 %1)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %11, %8
%17 = phi i32 [ %12, %11 ], [ %9, %8 ]
store i32 %17, i32* %2
br label %18
18: ; preds = %16, %14, %5
%19 = phi i32 [ %7, %5 ], [ %12, %14 ], [ 0, %16 ]
ret i32 %19
}