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


x86 assembly (clang, -O0):
<check_bump>:
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     1166 <check_bump+0x36>
jmp    1155 <check_bump+0x25>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     117e <check_bump+0x4e>
jmp    1196 <check_bump+0x66>
lea    0xe93(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <one_sensor_read@plt>
mov    %eax,-0xc(%rbp)
jmp    11b8 <check_bump+0x88>
lea    0xe7f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <one_sensor_read@plt>
mov    %eax,-0xc(%rbp)
jmp    11b8 <check_bump+0x88>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11cd <check_bump+0x9d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <check_bump+0xa3>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bump>:
push   %rax
test   %edi,%edi
je     1145 <check_bump+0x15>
mov    %edi,%edx
cmp    $0x1,%edi
jne    1160 <check_bump+0x30>
lea    0xec1(%rip),%rdi
jmp    114c <check_bump+0x1c>
lea    0xeb4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <one_sensor_read@plt>
test   %eax,%eax
js     115e <check_bump+0x2e>
mov    0x4(%rsp),%eax
pop    %rcx
ret
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"BFL\00"
@.str.1 = [4 x i8] c"BFR\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"get_front_ir_dist: invalid side number %d\0A\00"
define i32 @check_bump(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 %21
19: ; preds = %16
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %23
21: ; preds = %16
%22 = load i32, i32* %5
store i32 %22, i32* %2
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [4 x i8] c"BFL\00"
@.str.1 = [4 x i8] c"BFR\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"get_front_ir_dist: invalid side number %d\0A\00"
define i32 @check_bump(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
%13 = load i32, i32* %2
%14 = select i1 %12, i32 %11, i32 %13
ret i32 %14
}