#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*/ closeJetduino();
int /*<<< orphan*/ exit(int);
int openJetduino();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ servoAttach(int);
int /*<<< orphan*/ servoDetach(int);
int servoRead(int);
int /*<<< orphan*/ servoWrite(int, int);
int /*<<< orphan*/ usleep(int);
int main(void) {
  int adata;
  if (openJetduino() == -1)
    exit(1);
  printf("Attaching to servo\n");
  servoAttach(58);
  usleep(100000);
  printf("Moving servo to angle 0.\n");
  servoWrite(58, 0);
  usleep(100000);
  printf("Reading servo angle.\n");
  int cur_angle = servoRead(58);
  printf("Angle: %d\n", cur_angle);
  usleep(1000000);
  printf("Moving servo to angle 180.\n");
  servoWrite(58, 180);
  usleep(100000);
  printf("Reading servo angle.\n");
  cur_angle = servoRead(58);
  printf("Angle: %d\n", cur_angle);
  usleep(1000000);
  int num = 0, angle = 0;
  for (num = 0; num < 5; num++) {
    printf("Moving servo cycle %d\n", num);
    for (angle = 0; angle < 180; angle++) {
      servoWrite(58, angle);
      usleep(10000);
    }
    usleep(1000000);
  }
  printf("Detaching from servo\n");
  servoDetach(58);
  closeJetduino();
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <openJetduino@plt>
cmp    $0xffffffff,%eax
jne    11b9 <main+0x29>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
call   1050 <servoAttach@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
xor    %esi,%esi
call   1030 <servoWrite@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
call   1040 <servoRead@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xf4240,%edi
call   10b0 <usleep@plt>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
mov    $0xb4,%esi
call   1030 <servoWrite@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
call   1040 <servoRead@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xf4240,%edi
call   10b0 <usleep@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jge    1313 <main+0x183>
mov    -0x10(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xb4,-0x14(%rbp)
jge    12fb <main+0x16b>
mov    -0x14(%rbp),%esi
mov    $0x3a,%edi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12c9 <main+0x139>
mov    $0xf4240,%edi
call   10b0 <usleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12a7 <main+0x117>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3a,%edi
call   1090 <servoDetach@plt>
mov    $0x0,%al
call   1080 <closeJetduino@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <openJetduino@plt>
cmp    $0xffffffff,%eax
je     13e3 <main+0x243>
lea    0xe64(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
call   1060 <servoAttach@plt>
mov    $0x186a0,%edi
call   10c0 <usleep@plt>
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
xor    %esi,%esi
call   1030 <servoWrite@plt>
mov    $0x186a0,%edi
call   10c0 <usleep@plt>
lea    0xe69(%rip),%r14
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
call   1040 <servoRead@plt>
lea    0xde7(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xe18(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
mov    $0xb4,%esi
call   1030 <servoWrite@plt>
mov    $0x186a0,%edi
call   10c0 <usleep@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
call   1040 <servoRead@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xd88(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
nopl   0x0(%rax)
mov    $0x3a,%edi
mov    %ebx,%esi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0x1,%ebx
cmp    $0xb4,%ebx
jne    1290 <main+0xf0>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xd49(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3a,%edi
mov    %ebx,%esi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0x1,%ebx
cmp    $0xb4,%ebx
jne    12d0 <main+0x130>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xd09(%rip),%rdi
xor    %ebx,%ebx
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3a,%edi
mov    %ebx,%esi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0x1,%ebx
cmp    $0xb4,%ebx
jne    1310 <main+0x170>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xcc9(%rip),%rdi
xor    %ebx,%ebx
mov    $0x3,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3a,%edi
mov    %ebx,%esi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0x1,%ebx
cmp    $0xb4,%ebx
jne    1350 <main+0x1b0>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xc89(%rip),%rdi
xor    %ebx,%ebx
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3a,%edi
mov    %ebx,%esi
call   1030 <servoWrite@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0x1,%ebx
cmp    $0xb4,%ebx
jne    1390 <main+0x1f0>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
lea    0xcbc(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3a,%edi
call   10a0 <servoDetach@plt>
xor    %eax,%eax
call   1090 <closeJetduino@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Attaching to servo\0A\00"
@.str.1 = [26 x i8] c"Moving servo to angle 0.\0A\00"
@.str.2 = [22 x i8] c"Reading servo angle.\0A\00"
@.str.3 = [11 x i8] c"Angle: %d\0A\00"
@.str.4 = [28 x i8] c"Moving servo to angle 180.\0A\00"
@.str.5 = [23 x i8] c"Moving servo cycle %d\0A\00"
@.str.6 = [22 x i8] c"Detaching from servo\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (...) @openJetduino()
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @servoAttach(i32 58)
%13 = call i32 @usleep(i32 100000)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @servoWrite(i32 58, i32 0)
%16 = call i32 @usleep(i32 100000)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @servoRead(i32 58)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 @usleep(i32 1000000)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @servoWrite(i32 58, i32 180)
%24 = call i32 @usleep(i32 100000)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @servoRead(i32 58)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = call i32 @usleep(i32 1000000)
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %4
br label %30
30: ; preds = %48, %10
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 5
br i1 %32, label %33, label %51
33: ; preds = %30
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %34)
store i32 0, i32* %5
br label %36
36: ; preds = %43, %33
%37 = load i32, i32* %5
%38 = icmp slt i32 %37, 180
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = load i32, i32* %5
%41 = call i32 @servoWrite(i32 58, i32 %40)
%42 = call i32 @usleep(i32 10000)
br label %43
43: ; preds = %39
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %36
46: ; preds = %36
%47 = call i32 @usleep(i32 1000000)
br label %48
48: ; preds = %46
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %30
51: ; preds = %30
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @servoDetach(i32 58)
%54 = call i32 (...) @closeJetduino()
ret i32 1
}

LLVM IR (-O2):
@.str.3 = [11 x i8] c"Angle: %d\0A\00"
@.str.5 = [23 x i8] c"Moving servo cycle %d\0A\00"
@str = [19 x i8] c"Attaching to servo\00"
@str.7 = [25 x i8] c"Moving servo to angle 0.\00"
@str.9 = [27 x i8] c"Moving servo to angle 180.\00"
@str.10 = [21 x i8] c"Reading servo angle.\00"
@str.11 = [21 x i8] c"Detaching from servo\00"
define i32 @main() {
%1 = tail call i32 (...) @openJetduino()
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @exit(i32 1)
unreachable
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @servoAttach(i32 58)
%8 = tail call i32 @usleep(i32 100000)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%10 = tail call i32 @servoWrite(i32 58, i32 0)
%11 = tail call i32 @usleep(i32 100000)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%13 = tail call i32 @servoRead(i32 58)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 @usleep(i32 1000000)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
%17 = tail call i32 @servoWrite(i32 58, i32 180)
%18 = tail call i32 @usleep(i32 100000)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%20 = tail call i32 @servoRead(i32 58)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = tail call i32 @usleep(i32 1000000)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %24
24: ; preds = %5, %24
%25 = phi i32 [ 0, %5 ], [ %28, %24 ]
%26 = tail call i32 @servoWrite(i32 58, i32 %25)
%27 = tail call i32 @usleep(i32 10000)
%28 = add nuw nsw i32 %25, 1
%29 = icmp eq i32 %28, 180
br i1 %29, label %30, label %24
30: ; preds = %24
%31 = tail call i32 @usleep(i32 1000000)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %33
33: ; preds = %33, %30
%34 = phi i32 [ 0, %30 ], [ %37, %33 ]
%35 = tail call i32 @servoWrite(i32 58, i32 %34)
%36 = tail call i32 @usleep(i32 10000)
%37 = add nuw nsw i32 %34, 1
%38 = icmp eq i32 %37, 180
br i1 %38, label %39, label %33
39: ; preds = %33
%40 = tail call i32 @usleep(i32 1000000)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %42
42: ; preds = %42, %39
%43 = phi i32 [ 0, %39 ], [ %46, %42 ]
%44 = tail call i32 @servoWrite(i32 58, i32 %43)
%45 = tail call i32 @usleep(i32 10000)
%46 = add nuw nsw i32 %43, 1
%47 = icmp eq i32 %46, 180
br i1 %47, label %48, label %42
48: ; preds = %42
%49 = tail call i32 @usleep(i32 1000000)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 3)
br label %51
51: ; preds = %51, %48
%52 = phi i32 [ 0, %48 ], [ %55, %51 ]
%53 = tail call i32 @servoWrite(i32 58, i32 %52)
%54 = tail call i32 @usleep(i32 10000)
%55 = add nuw nsw i32 %52, 1
%56 = icmp eq i32 %55, 180
br i1 %56, label %57, label %51
57: ; preds = %51
%58 = tail call i32 @usleep(i32 1000000)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 4)
br label %60
60: ; preds = %60, %57
%61 = phi i32 [ 0, %57 ], [ %64, %60 ]
%62 = tail call i32 @servoWrite(i32 58, i32 %61)
%63 = tail call i32 @usleep(i32 10000)
%64 = add nuw nsw i32 %61, 1
%65 = icmp eq i32 %64, 180
br i1 %65, label %66, label %60
66: ; preds = %60
%67 = tail call i32 @usleep(i32 1000000)
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%69 = tail call i32 @servoDetach(i32 58)
%70 = tail call i32 (...) @closeJetduino()
ret i32 1
}