#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_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
int /*<<< orphan*/ robot_compose_n_send();
int /*<<< orphan*/ robot_compose_packet();
scalar_t__ robot_connect(char *);
int /*<<< orphan*/ robot_disconnect();
int /*<<< orphan*/ robot_init();
int /*<<< orphan*/ robot_reset();
int robot_send_packet();
int /*<<< orphan*/ robot_set_calibration(int, int);
int /*<<< orphan*/ robot_set_motor_a(int);
int /*<<< orphan*/ robot_set_motor_b(int);
int /*<<< orphan*/ robot_set_motor_flags(int);
int /*<<< orphan*/ robot_set_servo(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i;
  robot_init();
  if (0 != robot_connect("/dev/ttyUSB0")) {
    puts(strerror(errno));
    exit(EXIT_FAILURE);
  }
  robot_reset();
  sleep(1);
  robot_set_calibration(85, 192);
  robot_compose_packet();
  robot_send_packet();
  robot_set_servo(85);
  robot_compose_n_send();
  robot_set_motor_a(120);
  robot_set_motor_b(100);
  robot_set_motor_flags(0x80 | 0x40);
  robot_compose_packet();
  for (i = 0; i < 5; i++) {
    if (0x02 != robot_send_packet())
      break;
  }
  robot_disconnect();
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <robot_init@plt>
lea    0xddc(%rip),%rdi
call   1100 <robot_connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     125a <main+0x5a>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   1050 <puts@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1080 <robot_reset@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
mov    $0x55,%edi
mov    $0xc0,%esi
call   1070 <robot_set_calibration@plt>
mov    $0x0,%al
call   1120 <robot_compose_packet@plt>
mov    $0x0,%al
call   10b0 <robot_send_packet@plt>
mov    $0x55,%edi
call   10c0 <robot_set_servo@plt>
mov    $0x0,%al
call   1040 <robot_compose_n_send@plt>
mov    $0x78,%edi
call   10d0 <robot_set_motor_a@plt>
mov    $0x64,%edi
call   1060 <robot_set_motor_b@plt>
mov    $0xc0,%edi
call   1090 <robot_set_motor_flags@plt>
mov    $0x0,%al
call   1120 <robot_compose_packet@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    12fd <main+0xfd>
mov    $0x0,%al
call   10b0 <robot_send_packet@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
je     12ea <main+0xea>
jmp    12fd <main+0xfd>
jmp    12ef <main+0xef>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12c5 <main+0xc5>
mov    $0x0,%al
call   10a0 <robot_disconnect@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <robot_init@plt>
lea    0xdf1(%rip),%rdi
call   1100 <robot_connect@plt>
test   %rax,%rax
jne    12c3 <main+0xc3>
xor    %eax,%eax
call   1080 <robot_reset@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
mov    $0x55,%edi
mov    $0xc0,%esi
call   1070 <robot_set_calibration@plt>
xor    %eax,%eax
call   1120 <robot_compose_packet@plt>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
mov    $0x55,%edi
call   10c0 <robot_set_servo@plt>
xor    %eax,%eax
call   1040 <robot_compose_n_send@plt>
mov    $0x78,%edi
call   10d0 <robot_set_motor_a@plt>
mov    $0x64,%edi
call   1060 <robot_set_motor_b@plt>
mov    $0xc0,%edi
call   1090 <robot_set_motor_flags@plt>
xor    %eax,%eax
call   1120 <robot_compose_packet@plt>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
cmp    $0x2,%eax
jne    12b8 <main+0xb8>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
cmp    $0x2,%eax
jne    12b8 <main+0xb8>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
cmp    $0x2,%eax
jne    12b8 <main+0xb8>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
cmp    $0x2,%eax
jne    12b8 <main+0xb8>
xor    %eax,%eax
call   10b0 <robot_send_packet@plt>
xor    %eax,%eax
call   10a0 <robot_disconnect@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   1050 <puts@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @robot_init()
%8 = call i64 @robot_connect(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 0, %8
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @puts(i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 (...) @robot_reset()
%18 = call i32 @sleep(i32 1)
%19 = call i32 @robot_set_calibration(i32 85, i32 192)
%20 = call i32 (...) @robot_compose_packet()
%21 = call i32 (...) @robot_send_packet()
%22 = call i32 @robot_set_servo(i32 85)
%23 = call i32 (...) @robot_compose_n_send()
%24 = call i32 @robot_set_motor_a(i32 120)
%25 = call i32 @robot_set_motor_b(i32 100)
%26 = call i32 @robot_set_motor_flags(i32 192)
%27 = call i32 (...) @robot_compose_packet()
store i32 0, i32* %6
br label %28
28: ; preds = %36, %16
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 5
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = call i32 (...) @robot_send_packet()
%33 = icmp ne i32 2, %32
br i1 %33, label %34, label %35
34: ; preds = %31
br label %39
35: ; preds = %31
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %28
39: ; preds = %34, %28
%40 = call i32 (...) @robot_disconnect()
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @robot_init()
%4 = tail call i64 @robot_connect(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @puts(i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 (...) @robot_reset()
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 @robot_set_calibration(i32 85, i32 192)
%16 = tail call i32 (...) @robot_compose_packet()
%17 = tail call i32 (...) @robot_send_packet()
%18 = tail call i32 @robot_set_servo(i32 85)
%19 = tail call i32 (...) @robot_compose_n_send()
%20 = tail call i32 @robot_set_motor_a(i32 120)
%21 = tail call i32 @robot_set_motor_b(i32 100)
%22 = tail call i32 @robot_set_motor_flags(i32 192)
%23 = tail call i32 (...) @robot_compose_packet()
%24 = tail call i32 (...) @robot_send_packet()
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %37
26: ; preds = %12
%27 = tail call i32 (...) @robot_send_packet()
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = tail call i32 (...) @robot_send_packet()
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = tail call i32 (...) @robot_send_packet()
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 (...) @robot_send_packet()
br label %37
37: ; preds = %35, %32, %29, %26, %12
%38 = tail call i32 (...) @robot_disconnect()
ret i32 0
}