#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int gp2d120_to_dist(int);
int one_sensor_read(char *, int *);
int /*<<< orphan*/ stderr;
int get_side_ir_dist(int side) {
  int result = 0, value;
  switch (side) {
  case 0:
    result = one_sensor_read("ISL", &value);
    break;
  case 1:
    result = one_sensor_read("ISR", &value);
    break;
  default:
    fprintf(stderr, "get_front_ir_dist: invalid side number %d\n", side);
    exit(1);
  }
  if (result < 0)
    return 50;
  return gp2d120_to_dist(value);
}


x86 assembly (clang, -O0):
<get_side_ir_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1176 <get_side_ir_dist+0x36>
jmp    1165 <get_side_ir_dist+0x25>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     118e <get_side_ir_dist+0x4e>
jmp    11a6 <get_side_ir_dist+0x66>
lea    0xe83(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <one_sensor_read@plt>
mov    %eax,-0xc(%rbp)
jmp    11c8 <get_side_ir_dist+0x88>
lea    0xe6f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <one_sensor_read@plt>
mov    %eax,-0xc(%rbp)
jmp    11c8 <get_side_ir_dist+0x88>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe4f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11de <get_side_ir_dist+0x9e>
movl   $0x32,-0x4(%rbp)
jmp    11e9 <get_side_ir_dist+0xa9>
mov    -0x10(%rbp),%edi
call   1040 <gp2d120_to_dist@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_side_ir_dist>:
push   %rax
test   %edi,%edi
je     1155 <get_side_ir_dist+0x15>
mov    %edi,%edx
cmp    $0x1,%edi
jne    117c <get_side_ir_dist+0x3c>
lea    0xeb1(%rip),%rdi
jmp    115c <get_side_ir_dist+0x1c>
lea    0xea4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <one_sensor_read@plt>
test   %eax,%eax
js     1175 <get_side_ir_dist+0x35>
mov    0x4(%rsp),%edi
call   1040 <gp2d120_to_dist@plt>
pop    %rcx
ret
mov    $0x32,%eax
pop    %rcx
ret
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ISL\00"
@.str.1 = [4 x i8] c"ISR\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"get_front_ir_dist: invalid side number %d\0A\00"
define i32 @get_side_ir_dist(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* %3
switch i32 %6, label %11 [
i32 0, label %7
i32 1, label %9
]
7: ; preds = %1
%8 = call i32 @one_sensor_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 %8, i32* %4
br label %16
9: ; preds = %1
%10 = call i32 @one_sensor_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 %10, i32* %4
br label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* %3
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 50, i32* %2
br label %23
20: ; preds = %16
%21 = load i32, i32* %5
%22 = call i32 @gp2d120_to_dist(i32 %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %19
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [4 x i8] c"ISL\00"
@.str.1 = [4 x i8] c"ISR\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"get_front_ir_dist: invalid side number %d\0A\00"
define i32 @get_side_ir_dist(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
switch i32 %0, label %5 [
i32 0, label %9
i32 1, label %4
]
4: ; preds = %1
br label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1, %4
%10 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %1 ]
%11 = call i32 @one_sensor_read(i8* %10, i32* %2)
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 @gp2d120_to_dist(i32 %14)
br label %16
16: ; preds = %9, %13
%17 = phi i32 [ %15, %13 ], [ 50, %9 ]
ret i32 %17
}