#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 */
unsigned int I2CReadReg16(int, unsigned char, int);
int /*<<< orphan*/ I2CWriteReg16(int, unsigned char, int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int ina226Init(int fd, unsigned char i2cAddress) {
  unsigned int readData = 0;
  unsigned int writeData;
  unsigned int testFail = 0;
  printf("Configuring INA226\n");
  writeData = 0x8000;
  I2CWriteReg16(fd, i2cAddress, 0x00, writeData);
  writeData = 0x4f27;
  I2CWriteReg16(fd, i2cAddress, 0x00, writeData);
  writeData = 0x1400;
  I2CWriteReg16(fd, i2cAddress, 0x05, writeData);
  readData = I2CReadReg16(fd, i2cAddress, 0x00);
  printf("Config reg = 0x%0x\n", readData);
  if (readData != 0x4f27)
    testFail = 1;
  readData = I2CReadReg16(fd, i2cAddress, 0x05);
  printf("Cal reg = 0x%0x\n", readData);
  if (readData != 0x1400)
    testFail = 1;
  readData = I2CReadReg16(fd, i2cAddress, 0xff);
  printf("Die ID reg = 0x%0x\n", readData);
  if (testFail == 0)
    printf("--- INA226 Init Test passed\n");
  else
    printf("--- INA226 Init Test failed\n");
  printf("\n");
  return testFail;
}


x86 assembly (clang, -O0):
<ina226Init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x8000,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%ecx
xor    %edx,%edx
movzbl %al,%esi
call   1040 <I2CWriteReg16@plt>
movl   $0x4f27,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%ecx
xor    %edx,%edx
movzbl %al,%esi
call   1040 <I2CWriteReg16@plt>
movl   $0x1400,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%ecx
mov    $0x5,%edx
movzbl %al,%esi
call   1040 <I2CWriteReg16@plt>
mov    -0x4(%rbp),%edi
xor    %edx,%edx
movzbl -0x5(%rbp),%esi
call   1050 <I2CReadReg16@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x4f27,-0xc(%rbp)
je     11e4 <ina226Init+0xb4>
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x5,%edx
movzbl -0x5(%rbp),%esi
call   1050 <I2CReadReg16@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1400,-0xc(%rbp)
je     121d <ina226Init+0xed>
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xff,%edx
movzbl -0x5(%rbp),%esi
call   1050 <I2CReadReg16@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    125f <ina226Init+0x12f>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126d <ina226Init+0x13d>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ina226Init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xed6(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %r15d,%esi
xor    %edx,%edx
mov    $0x8000,%ecx
call   1060 <I2CWriteReg16@plt>
mov    %ebp,%edi
mov    %r15d,%esi
xor    %edx,%edx
mov    $0x4f27,%ecx
call   1060 <I2CWriteReg16@plt>
mov    %ebp,%edi
mov    %r15d,%esi
mov    $0x5,%edx
mov    $0x1400,%ecx
call   1060 <I2CWriteReg16@plt>
mov    %ebp,%edi
mov    %r15d,%esi
xor    %edx,%edx
call   1070 <I2CReadReg16@plt>
mov    %eax,%r14d
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    $0x4f27,%r14d
mov    %ebp,%edi
mov    %r15d,%esi
mov    $0x5,%edx
call   1070 <I2CReadReg16@plt>
mov    %eax,%ebx
lea    0xe38(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    $0x1400,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
mov    $0xff,%edx
call   1070 <I2CReadReg16@plt>
lea    0xe24(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
or     %r14d,%ebx
setne  %bpl
lea    0xe32(%rip),%rax
lea    0xe47(%rip),%rdi
cmovne %rax,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Configuring INA226\0A\00"
@.str.1 = [20 x i8] c"Config reg = 0x%0x\0A\00"
@.str.2 = [17 x i8] c"Cal reg = 0x%0x\0A\00"
@.str.3 = [20 x i8] c"Die ID reg = 0x%0x\0A\00"
@.str.4 = [29 x i8] c"--- INA226 Init Test passed\0A\00"
@.str.5 = [29 x i8] c"--- INA226 Init Test failed\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @ina226Init(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 32768, i32* %6
%9 = load i32, i32* %3
%10 = load i8, i8* %4
%11 = load i32, i32* %6
%12 = call i32 @I2CWriteReg16(i32 %9, i8 zeroext %10, i32 0, i32 %11)
store i32 20263, i32* %6
%13 = load i32, i32* %3
%14 = load i8, i8* %4
%15 = load i32, i32* %6
%16 = call i32 @I2CWriteReg16(i32 %13, i8 zeroext %14, i32 0, i32 %15)
store i32 5120, i32* %6
%17 = load i32, i32* %3
%18 = load i8, i8* %4
%19 = load i32, i32* %6
%20 = call i32 @I2CWriteReg16(i32 %17, i8 zeroext %18, i32 5, i32 %19)
%21 = load i32, i32* %3
%22 = load i8, i8* %4
%23 = call i32 @I2CReadReg16(i32 %21, i8 zeroext %22, i32 0)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, 20263
br i1 %27, label %28, label %29
28: ; preds = %2
store i32 1, i32* %7
br label %29
29: ; preds = %28, %2
%30 = load i32, i32* %3
%31 = load i8, i8* %4
%32 = call i32 @I2CReadReg16(i32 %30, i8 zeroext %31, i32 5)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 5120
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 1, i32* %7
br label %38
38: ; preds = %37, %29
%39 = load i32, i32* %3
%40 = load i8, i8* %4
%41 = call i32 @I2CReadReg16(i32 %39, i8 zeroext %40, i32 255)
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %50
48: ; preds = %38
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%52 = load i32, i32* %7
ret i32 %52
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Config reg = 0x%0x\0A\00"
@.str.2 = [17 x i8] c"Cal reg = 0x%0x\0A\00"
@.str.3 = [20 x i8] c"Die ID reg = 0x%0x\0A\00"
@str = [19 x i8] c"Configuring INA226\00"
@str.7 = [28 x i8] c"--- INA226 Init Test failed\00"
@str.8 = [28 x i8] c"--- INA226 Init Test passed\00"
define i32 @ina226Init(i32 %0, i8 zeroext %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @I2CWriteReg16(i32 %0, i8 zeroext %1, i32 0, i32 32768)
%5 = tail call i32 @I2CWriteReg16(i32 %0, i8 zeroext %1, i32 0, i32 20263)
%6 = tail call i32 @I2CWriteReg16(i32 %0, i8 zeroext %1, i32 5, i32 5120)
%7 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp ne i32 %7, 20263
%10 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 5)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp ne i32 %10, 5120
%13 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 255)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = or i1 %9, %12
%16 = select i1 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = zext i1 %15 to i32
%19 = tail call i32 @putchar(i32 10)
ret i32 %18
}