#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 */
scalar_t__ obd_reset(int);
int /*<<< orphan*/ obd_wait_until_echo(int, int);
int /*<<< orphan*/ obd_wait_until_on(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_blocking(int, int);
void obd_setup(int fd) {
  printf("Resetting the chip...");
  if (obd_reset(fd))
    printf("Success\n");
  else
    printf("FAILURE\n");
  obd_wait_until_echo(fd, false);
  printf("Making sure chip is working...");
  obd_wait_until_on(fd);
  printf("Success\n");
  set_blocking(fd, 1);
  printf("OBD is ready\n");
}


x86 assembly (clang, -O0):
<obd_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1030 <obd_reset@plt>
cmp    $0x0,%rax
je     118a <obd_setup+0x3a>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
jmp    1196 <obd_setup+0x46>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1070 <obd_wait_until_echo@plt>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <obd_wait_until_on@plt>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <set_blocking@plt>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obd_setup>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1030 <obd_reset@plt>
test   %rax,%rax
lea    0xeb2(%rip),%rdi
lea    0xec0(%rip),%r14
cmovne %r14,%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1080 <obd_wait_until_echo@plt>
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <obd_wait_until_on@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <set_blocking@plt>
lea    0xe73(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Resetting the chip...\00"
@.str.1 = [9 x i8] c"Success\0A\00"
@.str.2 = [9 x i8] c"FAILURE\0A\00"
@.str.3 = [31 x i8] c"Making sure chip is working...\00"
@.str.4 = [14 x i8] c"OBD is ready\0A\00"
define void @obd_setup(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
%5 = call i64 @obd_reset(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = load i32, i32* %2
%13 = call i32 @obd_wait_until_echo(i32 %12, i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = call i32 @obd_wait_until_on(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = call i32 @set_blocking(i32 %18, i32 1)
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Resetting the chip...\00"
@.str.3 = [31 x i8] c"Making sure chip is working...\00"
@str = [8 x i8] c"FAILURE\00"
@str.6 = [13 x i8] c"OBD is ready\00"
@str.7 = [8 x i8] c"Success\00"
define void @obd_setup(i32 %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @obd_reset(i32 %0)
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 @obd_wait_until_echo(i32 %0, i32 0)
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @obd_wait_until_on(i32 %0)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0))
%11 = tail call i32 @set_blocking(i32 %0, i32 1)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
ret void
}