#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 uint16_t;

/* Variables and functions */
int openAnalogSPI(char const *);
int /*<<< orphan*/ printf(char *, int);
int readRegister(int, int);
int /*<<< orphan*/ setAnalogSPI(int);
int /*<<< orphan*/ writeRegister(int, int);
int setAnalogIMU(const char *device) {
  int fd = openAnalogSPI(device);
  setAnalogSPI(fd);
  uint16_t temp = readRegister(fd, 0x5100);
  printf("reg 0x51: %x\n", temp);
  temp = readRegister(fd, 0x5000);
  printf("reg 0x50: %x\n", temp);
  while (temp != 0x1208) {
    writeRegister(fd, 0x0003);
    writeRegister(fd, 0x5112);
    writeRegister(fd, 0x5008);
    temp = readRegister(fd, 0x5100);
    printf("reg 0x51: %x\n", temp);
    temp = readRegister(fd, 0x5000);
    printf("reg 0x50: %x\n", temp);
  }
  writeRegister(fd, 0x0000);
  return fd;
}


x86 assembly (clang, -O0):
<setAnalogIMU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <openAnalogSPI@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <setAnalogSPI@plt>
mov    -0xc(%rbp),%edi
mov    $0x5100,%esi
call   1050 <readRegister@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0x5000,%esi
call   1050 <readRegister@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x1208,-0x10(%rbp)
je     1225 <setAnalogIMU+0xd5>
mov    -0xc(%rbp),%edi
mov    $0x3,%esi
call   1060 <writeRegister@plt>
mov    -0xc(%rbp),%edi
mov    $0x5112,%esi
call   1060 <writeRegister@plt>
mov    -0xc(%rbp),%edi
mov    $0x5008,%esi
call   1060 <writeRegister@plt>
mov    -0xc(%rbp),%edi
mov    $0x5100,%esi
call   1050 <readRegister@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0x5000,%esi
call   1050 <readRegister@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <setAnalogIMU+0x5e>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1060 <writeRegister@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setAnalogIMU>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1030 <openAnalogSPI@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <setAnalogSPI@plt>
mov    %ebx,%edi
mov    $0x5100,%esi
call   1050 <readRegister@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x5000,%esi
call   1050 <readRegister@plt>
mov    %eax,%ebp
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0x1208,%ebp
je     121a <setAnalogIMU+0xca>
lea    0xe56(%rip),%r14
lea    0xe5d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x3,%esi
call   1060 <writeRegister@plt>
mov    %ebx,%edi
mov    $0x5112,%esi
call   1060 <writeRegister@plt>
mov    %ebx,%edi
mov    $0x5008,%esi
call   1060 <writeRegister@plt>
mov    %ebx,%edi
mov    $0x5100,%esi
call   1050 <readRegister@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x5000,%esi
call   1050 <readRegister@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0x1208,%ebp
jne    11c0 <setAnalogIMU+0x70>
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <writeRegister@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"reg 0x51: %x\0A\00"
@.str.1 = [14 x i8] c"reg 0x50: %x\0A\00"
define i32 @setAnalogIMU(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @openAnalogSPI(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @setAnalogSPI(i32 %7)
%9 = load i32, i32* %3
%10 = call i32 @readRegister(i32 %9, i32 20736)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = call i32 @readRegister(i32 %13, i32 20480)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %20, %1
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 4616
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i32 @writeRegister(i32 %21, i32 3)
%23 = load i32, i32* %3
%24 = call i32 @writeRegister(i32 %23, i32 20754)
%25 = load i32, i32* %3
%26 = call i32 @writeRegister(i32 %25, i32 20488)
%27 = load i32, i32* %3
%28 = call i32 @readRegister(i32 %27, i32 20736)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = call i32 @readRegister(i32 %31, i32 20480)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %17
35: ; preds = %17
%36 = load i32, i32* %3
%37 = call i32 @writeRegister(i32 %36, i32 0)
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"reg 0x51: %x\0A\00"
@.str.1 = [14 x i8] c"reg 0x50: %x\0A\00"
define i32 @setAnalogIMU(i8* %0) {
%2 = tail call i32 @openAnalogSPI(i8* %0)
%3 = tail call i32 @setAnalogSPI(i32 %2)
%4 = tail call i32 @readRegister(i32 %2, i32 20736)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @readRegister(i32 %2, i32 20480)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %6, 4616
br i1 %8, label %18, label %9
9: ; preds = %1, %9
%10 = tail call i32 @writeRegister(i32 %2, i32 3)
%11 = tail call i32 @writeRegister(i32 %2, i32 20754)
%12 = tail call i32 @writeRegister(i32 %2, i32 20488)
%13 = tail call i32 @readRegister(i32 %2, i32 20736)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 @readRegister(i32 %2, i32 20480)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %15, 4616
br i1 %17, label %18, label %9
18: ; preds = %9, %1
%19 = tail call i32 @writeRegister(i32 %2, i32 0)
ret i32 %2
}