#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 analogRead(int);
float getJoystick(int mode, int pin) {
  if (mode == 0) {
    return analogRead(pin);
  } else if (mode == 1) {
    return analogRead(pin + 1);
  } else {
    return analogRead(pin) > 1000;
  }
}


x86 assembly (clang, -O0):
<getJoystick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    113e <getJoystick+0x2e>
mov    -0xc(%rbp),%edi
call   1030 <analogRead@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    117f <getJoystick+0x6f>
cmpl   $0x1,-0x8(%rbp)
jne    1161 <getJoystick+0x51>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <analogRead@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    117f <getJoystick+0x6f>
mov    -0xc(%rbp),%edi
call   1030 <analogRead@plt>
cmp    $0x3e8,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getJoystick>:
push   %rax
cmp    $0x1,%edi
je     112d <getJoystick+0x1d>
test   %edi,%edi
je     1130 <getJoystick+0x20>
mov    %esi,%edi
call   1030 <analogRead@plt>
cmp    $0x3e9,%eax
jge    113d <getJoystick+0x2d>
xorps  %xmm0,%xmm0
pop    %rax
ret
add    $0x1,%esi
mov    %esi,%edi
call   1030 <analogRead@plt>
cvtsi2ss %eax,%xmm0
pop    %rax
ret
movss  0xebb(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @getJoystick(i32 %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %5
%10 = call i32 @analogRead(i32 %9)
%11 = sitofp i32 %10 to float
store float %11, float* %3
br label %26
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = call i32 @analogRead(i32 %17)
%19 = sitofp i32 %18 to float
store float %19, float* %3
br label %26
20: ; preds = %12
%21 = load i32, i32* %5
%22 = call i32 @analogRead(i32 %21)
%23 = icmp sgt i32 %22, 1000
%24 = zext i1 %23 to i32
%25 = sitofp i32 %24 to float
store float %25, float* %3
br label %26
26: ; preds = %20, %15, %8
%27 = load float, float* %3
ret float %27
}

LLVM IR (-O2):
define float @getJoystick(i32 %0, i32 %1) {
switch i32 %0, label %10 [
i32 0, label %3
i32 1, label %6
]
3: ; preds = %2
%4 = tail call i32 @analogRead(i32 %1)
%5 = sitofp i32 %4 to float
br label %14
6: ; preds = %2
%7 = add nsw i32 %1, 1
%8 = tail call i32 @analogRead(i32 %7)
%9 = sitofp i32 %8 to float
br label %14
10: ; preds = %2
%11 = tail call i32 @analogRead(i32 %1)
%12 = icmp sgt i32 %11, 1000
%13 = uitofp i1 %12 to float
br label %14
14: ; preds = %10, %6, %3
%15 = phi float [ %5, %3 ], [ %9, %6 ], [ %13, %10 ]
ret float %15
}