#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);
unsigned int twosComplement(unsigned int);
void ina226GetMeas(int fd, unsigned char i2cAddress, char *desc, float *busVolt,
                   unsigned int *current) {
  unsigned int readData = 0;
  readData = I2CReadReg16(fd, i2cAddress, 0x01);
  readData = twosComplement(readData);
  readData = I2CReadReg16(fd, i2cAddress, 0x02);
  readData = twosComplement(readData);
  *busVolt = ((float)readData * 0.00125f);
  readData = I2CReadReg16(fd, i2cAddress, 0x03);
  readData = I2CReadReg16(fd, i2cAddress, 0x04);
  readData = twosComplement(readData);
  *current = (unsigned int)((float)readData * 0.1f);
}


x86 assembly (clang, -O0):
<ina226GetMeas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
mov    $0x1,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <twosComplement@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
mov    $0x2,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <twosComplement@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  0xe6e(%rip),%xmm1
mulss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
mov    $0x3,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x5(%rbp),%esi
mov    $0x4,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <twosComplement@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  0xe23(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ina226GetMeas>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0x1,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,%edi
call   1030 <twosComplement@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x2,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,%edi
call   1030 <twosComplement@plt>
mov    %eax,%eax
cvtsi2ss %rax,%xmm0
mulss  0xe9a(%rip),%xmm0
movss  %xmm0,(%r15)
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x3,%edx
call   1040 <I2CReadReg16@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x4,%edx
call   1040 <I2CReadReg16@plt>
mov    %eax,%edi
call   1030 <twosComplement@plt>
mov    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mulss  0xe64(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ina226GetMeas(i32 %0, i8 zeroext %1, i8* %2, float* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca float*
%10 = alloca i32*
%11 = alloca i32
store i32 %0, i32* %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store float* %3, float** %9
store i32* %4, i32** %10
store i32 0, i32* %11
%12 = load i32, i32* %6
%13 = load i8, i8* %7
%14 = call i32 @I2CReadReg16(i32 %12, i8 zeroext %13, i32 1)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = call i32 @twosComplement(i32 %15)
store i32 %16, i32* %11
%17 = load i32, i32* %6
%18 = load i8, i8* %7
%19 = call i32 @I2CReadReg16(i32 %17, i8 zeroext %18, i32 2)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = call i32 @twosComplement(i32 %20)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = uitofp i32 %22 to float
%24 = fmul float %23, 0x3F547AE140000000
%25 = load float*, float** %9
store float %24, float* %25
%26 = load i32, i32* %6
%27 = load i8, i8* %7
%28 = call i32 @I2CReadReg16(i32 %26, i8 zeroext %27, i32 3)
store i32 %28, i32* %11
%29 = load i32, i32* %6
%30 = load i8, i8* %7
%31 = call i32 @I2CReadReg16(i32 %29, i8 zeroext %30, i32 4)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = call i32 @twosComplement(i32 %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = uitofp i32 %34 to float
%36 = fmul float %35, 0x3FB99999A0000000
%37 = fptoui float %36 to i32
%38 = load i32*, i32** %10
store i32 %37, i32* %38
ret void
}

LLVM IR (-O2):
define void @ina226GetMeas(i32 %0, i8 zeroext %1, i8* nocapture readnone %2, float* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 1)
%7 = tail call i32 @twosComplement(i32 %6)
%8 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 2)
%9 = tail call i32 @twosComplement(i32 %8)
%10 = uitofp i32 %9 to float
%11 = fmul float %10, 0x3F547AE140000000
store float %11, float* %3
%12 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 3)
%13 = tail call i32 @I2CReadReg16(i32 %0, i8 zeroext %1, i32 4)
%14 = tail call i32 @twosComplement(i32 %13)
%15 = uitofp i32 %14 to float
%16 = fmul float %15, 0x3FB99999A0000000
%17 = fptoui float %16 to i32
store i32 %17, i32* %4
ret void
}