#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 GET32(int);
int /*<<< orphan*/ PUT32(int, int);
int /*<<< orphan*/ wait_i2c_done();
unsigned int read_magnitude() {
  unsigned int magnitude;
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x10), 0xFB);
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7));
  wait_i2c_done();
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7) | (1 << 4) | 1);
  wait_i2c_done();
  magnitude = (GET32((0x20804000 + 0x10))) << 8;
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x10), 0xFC);
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7));
  wait_i2c_done();
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7) | (1 << 4) | 1);
  wait_i2c_done();
  magnitude |= (GET32((0x20804000 + 0x10)));
  return magnitude;
}


x86 assembly (clang, -O0):
<read_magnitude>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xfb,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1040 <PUT32@plt>
mov    $0x0,%al
call   1030 <wait_i2c_done@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1040 <PUT32@plt>
mov    $0x0,%al
call   1030 <wait_i2c_done@plt>
mov    $0x20804010,%edi
call   1050 <GET32@plt>
shl    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xfc,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1040 <PUT32@plt>
mov    $0x0,%al
call   1030 <wait_i2c_done@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1040 <PUT32@plt>
mov    $0x0,%al
call   1030 <wait_i2c_done@plt>
mov    $0x20804010,%edi
call   1050 <GET32@plt>
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_magnitude>:
push   %rbx
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xfb,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1040 <PUT32@plt>
xor    %eax,%eax
call   1030 <wait_i2c_done@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1040 <PUT32@plt>
xor    %eax,%eax
call   1030 <wait_i2c_done@plt>
mov    $0x20804010,%edi
call   1050 <GET32@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xfc,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1040 <PUT32@plt>
xor    %eax,%eax
call   1030 <wait_i2c_done@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1040 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1040 <PUT32@plt>
xor    %eax,%eax
call   1030 <wait_i2c_done@plt>
mov    $0x20804010,%edi
call   1050 <GET32@plt>
or     %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @read_magnitude() {
%1 = alloca i32
%2 = call i32 @PUT32(i32 545275908, i32 770)
%3 = call i32 @PUT32(i32 545275920, i32 251)
%4 = call i32 @PUT32(i32 545275904, i32 32896)
%5 = call i32 (...) @wait_i2c_done()
%6 = call i32 @PUT32(i32 545275908, i32 770)
%7 = call i32 @PUT32(i32 545275904, i32 32913)
%8 = call i32 (...) @wait_i2c_done()
%9 = call i32 @GET32(i32 545275920)
%10 = shl i32 %9, 8
store i32 %10, i32* %1
%11 = call i32 @PUT32(i32 545275908, i32 770)
%12 = call i32 @PUT32(i32 545275920, i32 252)
%13 = call i32 @PUT32(i32 545275904, i32 32896)
%14 = call i32 (...) @wait_i2c_done()
%15 = call i32 @PUT32(i32 545275908, i32 770)
%16 = call i32 @PUT32(i32 545275904, i32 32913)
%17 = call i32 (...) @wait_i2c_done()
%18 = call i32 @GET32(i32 545275920)
%19 = load i32, i32* %1
%20 = or i32 %19, %18
store i32 %20, i32* %1
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
define i32 @read_magnitude() {
%1 = tail call i32 @PUT32(i32 545275908, i32 770)
%2 = tail call i32 @PUT32(i32 545275920, i32 251)
%3 = tail call i32 @PUT32(i32 545275904, i32 32896)
%4 = tail call i32 (...) @wait_i2c_done()
%5 = tail call i32 @PUT32(i32 545275908, i32 770)
%6 = tail call i32 @PUT32(i32 545275904, i32 32913)
%7 = tail call i32 (...) @wait_i2c_done()
%8 = tail call i32 @GET32(i32 545275920)
%9 = shl i32 %8, 8
%10 = tail call i32 @PUT32(i32 545275908, i32 770)
%11 = tail call i32 @PUT32(i32 545275920, i32 252)
%12 = tail call i32 @PUT32(i32 545275904, i32 32896)
%13 = tail call i32 (...) @wait_i2c_done()
%14 = tail call i32 @PUT32(i32 545275908, i32 770)
%15 = tail call i32 @PUT32(i32 545275904, i32 32913)
%16 = tail call i32 (...) @wait_i2c_done()
%17 = tail call i32 @GET32(i32 545275920)
%18 = or i32 %17, %9
ret i32 %18
}