#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 */
char i2c_read8(char);
int /*<<< orphan*/ i2c_write(char, int);
int /*<<< orphan*/ printf(char *, float, float);
int /*<<< orphan*/ usleep(int);
short int mag3110_readx(char addr) {
  char m, l;
  int r;
  i2c_write(addr, 0x01);
  usleep(2);
  m = i2c_read8(addr);
  usleep(2);
  i2c_write(addr, 0x02);
  usleep(5);
  l = i2c_read8(addr);
  printf("%f %f\n", (float)m, (float)l);
  r = (int)(l | (m << 8));
  return r;
}


x86 assembly (clang, -O0):
<mag3110_readx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
mov    $0x1,%esi
call   1040 <i2c_write@plt>
mov    $0x2,%edi
mov    %edi,-0xc(%rbp)
call   1060 <usleep@plt>
movsbl -0x1(%rbp),%edi
call   1050 <i2c_read8@plt>
mov    -0xc(%rbp),%edi
mov    %al,-0x2(%rbp)
call   1060 <usleep@plt>
mov    -0xc(%rbp),%esi
movsbl -0x1(%rbp),%edi
call   1040 <i2c_write@plt>
mov    $0x5,%edi
call   1060 <usleep@plt>
movsbl -0x1(%rbp),%edi
call   1050 <i2c_read8@plt>
mov    %al,-0x3(%rbp)
movsbl -0x2(%rbp),%eax
cvtsi2ss %eax,%xmm0
movsbl -0x3(%rbp),%eax
cvtsi2ss %eax,%xmm1
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x3(%rbp),%eax
movsbl -0x2(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cwtl
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mag3110_readx>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%esi
call   1040 <i2c_write@plt>
mov    $0x2,%edi
call   1060 <usleep@plt>
mov    %ebx,%edi
call   1050 <i2c_read8@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1060 <usleep@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <i2c_write@plt>
mov    $0x5,%edi
call   1060 <usleep@plt>
mov    %ebx,%edi
call   1050 <i2c_read8@plt>
movsbl %bpl,%ebx
cvtsi2ss %ebx,%xmm0
movsbl %al,%ebp
cvtsi2ss %ebp,%xmm1
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
movzbl %bl,%eax
shl    $0x8,%eax
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%f %f\0A\00"
define signext i16 @mag3110_readx(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i8 %0, i8* %2
%6 = load i8, i8* %2
%7 = call i32 @i2c_write(i8 signext %6, i32 1)
%8 = call i32 @usleep(i32 2)
%9 = load i8, i8* %2
%10 = call signext i8 @i2c_read8(i8 signext %9)
store i8 %10, i8* %3
%11 = call i32 @usleep(i32 2)
%12 = load i8, i8* %2
%13 = call i32 @i2c_write(i8 signext %12, i32 2)
%14 = call i32 @usleep(i32 5)
%15 = load i8, i8* %2
%16 = call signext i8 @i2c_read8(i8 signext %15)
store i8 %16, i8* %4
%17 = load i8, i8* %3
%18 = sitofp i8 %17 to float
%19 = load i8, i8* %4
%20 = sitofp i8 %19 to float
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %18, float %20)
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = shl i32 %25, 8
%27 = or i32 %23, %26
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = trunc i32 %28 to i16
ret i16 %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"%f %f\0A\00"
define signext i16 @mag3110_readx(i8 signext %0) {
%2 = tail call i32 @i2c_write(i8 signext %0, i32 1)
%3 = tail call i32 @usleep(i32 2)
%4 = tail call signext i8 @i2c_read8(i8 signext %0)
%5 = tail call i32 @usleep(i32 2)
%6 = tail call i32 @i2c_write(i8 signext %0, i32 2)
%7 = tail call i32 @usleep(i32 5)
%8 = tail call signext i8 @i2c_read8(i8 signext %0)
%9 = sitofp i8 %4 to float
%10 = sitofp i8 %8 to float
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %9, float %10)
%12 = sext i8 %8 to i16
%13 = zext i8 %4 to i16
%14 = shl nuw i16 %13, 8
%15 = or i16 %14, %12
ret i16 %15
}