#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*/ usleep(int);
short int mag3110_ready(char addr) {
  char m, l;
  int r;
  i2c_write(addr, 0x03);
  usleep(2);
  m = i2c_read8(addr);
  usleep(2);
  i2c_write(addr, 0x04);
  usleep(2);
  l = i2c_read8(addr);
  r = ((m << 8) + l);
  return r;
}


x86 assembly (clang, -O0):
<mag3110_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x3,%esi
movsbl -0x1(%rbp),%edi
call   1030 <i2c_write@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
movsbl -0x1(%rbp),%edi
call   1040 <i2c_read8@plt>
mov    %al,-0x2(%rbp)
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x4,%esi
movsbl -0x1(%rbp),%edi
call   1030 <i2c_write@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
movsbl -0x1(%rbp),%edi
call   1040 <i2c_read8@plt>
mov    %al,-0x3(%rbp)
movsbl -0x2(%rbp),%eax
shl    $0x8,%eax
movsbl -0x3(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cwtl
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mag3110_ready>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x3,%esi
call   1030 <i2c_write@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
call   1040 <i2c_read8@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
mov    $0x4,%esi
call   1030 <i2c_write@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
call   1040 <i2c_read8@plt>
movzbl %bpl,%ecx
shl    $0x8,%ecx
movsbl %al,%eax
add    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @mag3110_ready(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 3)
%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 4)
%14 = call i32 @usleep(i32 2)
%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 = sext i8 %17 to i32
%19 = shl i32 %18, 8
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = add nsw i32 %19, %21
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = trunc i32 %23 to i16
ret i16 %24
}

LLVM IR (-O2):
define signext i16 @mag3110_ready(i8 signext %0) {
%2 = tail call i32 @i2c_write(i8 signext %0, i32 3)
%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 4)
%7 = tail call i32 @usleep(i32 2)
%8 = tail call signext i8 @i2c_read8(i8 signext %0)
%9 = zext i8 %4 to i16
%10 = shl nuw i16 %9, 8
%11 = sext i8 %8 to i16
%12 = add i16 %10, %11
ret i16 %12
}