#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 */
int GET32(int);
int /*<<< orphan*/ PUT32(int, int);
int /*<<< orphan*/ puts(char *);
scalar_t__ wait_i2c_done();
unsigned int read_angle() {
  unsigned int angle;
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x10), 0xFF);
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7));
  if (wait_i2c_done())
    puts("i2c timed out\r\n");
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7) | (1 << 4) | 1);
  if (wait_i2c_done())
    puts("i2c timed out\r\n");
  angle = (GET32((0x20804000 + 0x10)) & 0xFF) << 6;
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x10), 0x00);
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7));
  if (wait_i2c_done())
    puts("i2c timed out\r\n");
  PUT32((0x20804000 + 0x04), (1 << 9) | (1 << 8) | (1 << 1));
  PUT32((0x20804000 + 0x00), (1 << 15) | (1 << 7) | (1 << 4) | 1);
  if (wait_i2c_done())
    puts("i2c timed out\r\n");
  angle |= (GET32((0x20804000 + 0x10)) & 0x3F);
  return angle;
}


x86 assembly (clang, -O0):
<read_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xff,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1050 <PUT32@plt>
mov    $0x0,%al
call   1040 <wait_i2c_done@plt>
cmp    $0x0,%rax
je     1192 <read_angle+0x52>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1050 <PUT32@plt>
mov    $0x0,%al
call   1040 <wait_i2c_done@plt>
cmp    $0x0,%rax
je     11cd <read_angle+0x8d>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804010,%edi
call   1060 <GET32@plt>
and    $0xff,%eax
shl    $0x6,%eax
mov    %eax,-0x4(%rbp)
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804010,%edi
xor    %esi,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1050 <PUT32@plt>
mov    $0x0,%al
call   1040 <wait_i2c_done@plt>
cmp    $0x0,%rax
je     1229 <read_angle+0xe9>
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1050 <PUT32@plt>
mov    $0x0,%al
call   1040 <wait_i2c_done@plt>
cmp    $0x0,%rax
je     1264 <read_angle+0x124>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804010,%edi
call   1060 <GET32@plt>
and    $0x3f,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_angle>:
push   %rbx
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804010,%edi
mov    $0xff,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1050 <PUT32@plt>
xor    %eax,%eax
call   1040 <wait_i2c_done@plt>
test   %rax,%rax
je     1186 <read_angle+0x46>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1050 <PUT32@plt>
xor    %eax,%eax
call   1040 <wait_i2c_done@plt>
test   %rax,%rax
je     11bc <read_angle+0x7c>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804010,%edi
call   1060 <GET32@plt>
mov    %eax,%ebx
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804010,%edi
xor    %esi,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8080,%esi
call   1050 <PUT32@plt>
xor    %eax,%eax
call   1040 <wait_i2c_done@plt>
test   %rax,%rax
je     120a <read_angle+0xca>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x20804004,%edi
mov    $0x302,%esi
call   1050 <PUT32@plt>
mov    $0x20804000,%edi
mov    $0x8091,%esi
call   1050 <PUT32@plt>
xor    %eax,%eax
call   1040 <wait_i2c_done@plt>
test   %rax,%rax
je     1240 <read_angle+0x100>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
movzbl %bl,%ebx
shl    $0x6,%ebx
mov    $0x20804010,%edi
call   1060 <GET32@plt>
and    $0x3f,%eax
or     %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"i2c timed out\0D\0A\00"
define i32 @read_angle() {
%1 = alloca i32
%2 = call i32 @PUT32(i32 545275908, i32 770)
%3 = call i32 @PUT32(i32 545275920, i32 255)
%4 = call i32 @PUT32(i32 545275904, i32 32896)
%5 = call i64 (...) @wait_i2c_done()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @PUT32(i32 545275908, i32 770)
%11 = call i32 @PUT32(i32 545275904, i32 32913)
%12 = call i64 (...) @wait_i2c_done()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = call i32 @GET32(i32 545275920)
%18 = and i32 %17, 255
%19 = shl i32 %18, 6
store i32 %19, i32* %1
%20 = call i32 @PUT32(i32 545275908, i32 770)
%21 = call i32 @PUT32(i32 545275920, i32 0)
%22 = call i32 @PUT32(i32 545275904, i32 32896)
%23 = call i64 (...) @wait_i2c_done()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %16
%28 = call i32 @PUT32(i32 545275908, i32 770)
%29 = call i32 @PUT32(i32 545275904, i32 32913)
%30 = call i64 (...) @wait_i2c_done()
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = call i32 @GET32(i32 545275920)
%36 = and i32 %35, 63
%37 = load i32, i32* %1
%38 = or i32 %37, %36
store i32 %38, i32* %1
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [16 x i8] c"i2c timed out\0D\0A\00"
define i32 @read_angle() {
%1 = tail call i32 @PUT32(i32 545275908, i32 770)
%2 = tail call i32 @PUT32(i32 545275920, i32 255)
%3 = tail call i32 @PUT32(i32 545275904, i32 32896)
%4 = tail call i64 (...) @wait_i2c_done()
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = tail call i32 @PUT32(i32 545275908, i32 770)
%10 = tail call i32 @PUT32(i32 545275904, i32 32913)
%11 = tail call i64 (...) @wait_i2c_done()
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = tail call i32 @GET32(i32 545275920)
%17 = tail call i32 @PUT32(i32 545275908, i32 770)
%18 = tail call i32 @PUT32(i32 545275920, i32 0)
%19 = tail call i32 @PUT32(i32 545275904, i32 32896)
%20 = tail call i64 (...) @wait_i2c_done()
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = tail call i32 @PUT32(i32 545275908, i32 770)
%26 = tail call i32 @PUT32(i32 545275904, i32 32913)
%27 = tail call i64 (...) @wait_i2c_done()
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = shl i32 %16, 6
%33 = and i32 %32, 16320
%34 = tail call i32 @GET32(i32 545275920)
%35 = and i32 %34, 63
%36 = or i32 %35, %33
ret i32 %36
}