#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;
typedef int int32_t;

/* Variables and functions */
int I2C_Recv2(int /*<<< orphan*/);
int /*<<< orphan*/ I2C_Send1(int /*<<< orphan*/, int);
int /*<<< orphan*/ I2C_Send3(int /*<<< orphan*/, int, int, int);
int32_t lightsensorend(uint8_t slaveAddress) {
  uint16_t raw, config;
  I2C_Send1(slaveAddress, 0x00);
  raw = I2C_Recv2(slaveAddress);
  I2C_Send1(slaveAddress, 0x01);
  config = I2C_Recv2(slaveAddress);
  I2C_Send3(slaveAddress, 0x01, (config & 0xFF00) >> 8,
            (config & 0x00FF) & ~0x0010);
  I2C_Send3(slaveAddress, 0x01, (config & 0xFF00) >> 8,
            (config & 0x00FF) | 0x0010);
  return (1 << (raw >> 12)) * (raw & 0x0FFF);
}


x86 assembly (clang, -O0):
<lightsensorend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1050 <I2C_Send1@plt>
mov    -0x4(%rbp),%edi
call   1030 <I2C_Recv2@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <I2C_Send1@plt>
mov    -0x4(%rbp),%edi
call   1030 <I2C_Recv2@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
and    $0xff00,%edx
sar    $0x8,%edx
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
and    $0xffffffef,%ecx
mov    $0x1,%esi
call   1040 <I2C_Send3@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
and    $0xff00,%edx
sar    $0x8,%edx
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
or     $0x10,%ecx
mov    $0x1,%esi
call   1040 <I2C_Send3@plt>
mov    -0x8(%rbp),%ecx
sar    $0xc,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x8(%rbp),%ecx
and    $0xfff,%ecx
imul   %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lightsensorend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %esi,%esi
call   1050 <I2C_Send1@plt>
mov    %ebp,%edi
call   1030 <I2C_Recv2@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <I2C_Send1@plt>
mov    %ebp,%edi
call   1030 <I2C_Recv2@plt>
mov    %eax,%ebx
movzbl %bh,%edx
and    $0xef,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
mov    %edx,%r15d
mov    %ebx,%ecx
call   1040 <I2C_Send3@plt>
or     $0x10,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
call   1040 <I2C_Send3@plt>
mov    %r14d,%ecx
shr    $0xc,%ecx
and    $0xfff,%r14d
shl    %cl,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lightsensorend(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @I2C_Send1(i32 %5, i32 0)
%7 = load i32, i32* %2
%8 = call i32 @I2C_Recv2(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = call i32 @I2C_Send1(i32 %9, i32 1)
%11 = load i32, i32* %2
%12 = call i32 @I2C_Recv2(i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = and i32 %14, 65280
%16 = ashr i32 %15, 8
%17 = load i32, i32* %4
%18 = and i32 %17, 255
%19 = and i32 %18, -17
%20 = call i32 @I2C_Send3(i32 %13, i32 1, i32 %16, i32 %19)
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = and i32 %22, 65280
%24 = ashr i32 %23, 8
%25 = load i32, i32* %4
%26 = and i32 %25, 255
%27 = or i32 %26, 16
%28 = call i32 @I2C_Send3(i32 %21, i32 1, i32 %24, i32 %27)
%29 = load i32, i32* %3
%30 = ashr i32 %29, 12
%31 = shl i32 1, %30
%32 = load i32, i32* %3
%33 = and i32 %32, 4095
%34 = mul nsw i32 %31, %33
ret i32 %34
}

LLVM IR (-O2):
define i32 @lightsensorend(i32 %0) {
%2 = tail call i32 @I2C_Send1(i32 %0, i32 0)
%3 = tail call i32 @I2C_Recv2(i32 %0)
%4 = tail call i32 @I2C_Send1(i32 %0, i32 1)
%5 = tail call i32 @I2C_Recv2(i32 %0)
%6 = lshr i32 %5, 8
%7 = and i32 %6, 255
%8 = and i32 %5, 239
%9 = tail call i32 @I2C_Send3(i32 %0, i32 1, i32 %7, i32 %8)
%10 = or i32 %8, 16
%11 = tail call i32 @I2C_Send3(i32 %0, i32 1, i32 %7, i32 %10)
%12 = ashr i32 %3, 12
%13 = and i32 %3, 4095
%14 = shl i32 %13, %12
ret i32 %14
}