#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 */
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int pwmFreq(int, float);
int /*<<< orphan*/ pwmPulse(int, int, int /*<<< orphan*/, int);
int resetDev(int);
int /*<<< orphan*/ usleep(int);
main() {
  int fh = open("/dev/i2c-3", O_RDWR);
  printf("Opening i2c port...\n");
  if (fh != 3)
    printf("ERROR opening i2c port.\n");
  else
    printf("The i2c port is open.\n");
  printf("Reseting device...\n");
  if (resetDev(fh) != 1)
    printf("ERROR: Device not reset.\n");
  else
    printf("Device is reset and ready for use.\n");
  float freq = 60;
  if (pwmFreq(fh, freq) != 1)
    printf("ERROR: setting pwm frequency\n");
  else
    printf("Frequency set to %f Hz.\n", freq);
  uint16_t pl1 = 150;
  uint16_t pl2 = 600;
  int switcher = 0;
  int loops = 1;
  int servo, servo1, servo2;
  int servonum = 0;
  uint16_t pl;
  while (loops <= 10) {
    printf("Pulse %d:\n", loops);
    for (servo = 0; servo < 8; servo++) {
      servo1 = 2 * servo;
      servo2 = 2 * servo + 1;
      if (switcher == 0) {
        pwmPulse(fh, servo1, 0, pl1);
        pwmPulse(fh, servo2, 0, pl2);
      } else {
        pwmPulse(fh, servo1, 0, pl2);
        pwmPulse(fh, servo2, 0, pl1);
      }
    }
    if (switcher == 0)
      switcher = 1;
    else
      switcher = 0;
    usleep(1000000);
    loops++;
  }
  resetDev(fh);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11b2 <main+0x52>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c0 <main+0x60>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <resetDev@plt>
cmp    $0x1,%eax
je     11f2 <main+0x92>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1200 <main+0xa0>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  0xdf8(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
movss  -0xc(%rbp),%xmm0
call   1030 <pwmFreq@plt>
cmp    $0x1,%eax
je     1236 <main+0xd6>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124d <main+0xed>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x96,-0x10(%rbp)
movl   $0x258,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jg     1348 <main+0x1e8>
mov    -0x1c(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x8,-0x20(%rbp)
jge    1313 <main+0x1b3>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12e0 <main+0x180>
mov    -0x8(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%ecx
xor    %edx,%edx
call   1060 <pwmPulse@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
call   1060 <pwmPulse@plt>
jmp    1300 <main+0x1a0>
mov    -0x8(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
call   1060 <pwmPulse@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%ecx
xor    %edx,%edx
call   1060 <pwmPulse@plt>
jmp    1305 <main+0x1a5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1292 <main+0x132>
cmpl   $0x0,-0x18(%rbp)
jne    1329 <main+0x1c9>
movl   $0x1,-0x18(%rbp)
jmp    1330 <main+0x1d0>
movl   $0x0,-0x18(%rbp)
mov    $0xf4240,%edi
call   1080 <usleep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1270 <main+0x110>
mov    -0x8(%rbp),%edi
call   1050 <resetDev@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r12d
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x3,%r12d
lea    0xea9(%rip),%rax
lea    0xf24(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
call   1060 <resetDev@plt>
cmp    $0x1,%eax
lea    0xea4(%rip),%rax
lea    0xedd(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
movss  0xe10(%rip),%xmm0
mov    %r12d,%edi
call   1040 <pwmFreq@plt>
cmp    $0x1,%eax
jne    1215 <main+0xa5>
lea    0xe17(%rip),%rdi
movsd  0xdfc(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1221 <main+0xb1>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
mov    $0x258,%r13d
xor    %r14d,%r14d
lea    0xdfd(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
mov    $0x258,%ebx
mov    $0x96,%eax
cmove  %eax,%ebx
mov    $0x96,%ebp
cmove  %r13d,%ebp
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x1,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x2,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x3,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x4,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x5,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x6,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x7,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x8,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0x9,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xa,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xb,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xc,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xd,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xe,%esi
xor    %edx,%edx
mov    %ebx,%ecx
call   1070 <pwmPulse@plt>
mov    %r12d,%edi
mov    $0xf,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1070 <pwmPulse@plt>
xor    $0x1,%r14d
mov    $0xf4240,%edi
call   1090 <usleep@plt>
add    $0x1,%r15d
cmp    $0xb,%r15d
jne    1230 <main+0xc0>
mov    %r12d,%edi
call   1060 <resetDev@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-3\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"Opening i2c port...\0A\00"
@.str.2 = [25 x i8] c"ERROR opening i2c port.\0A\00"
@.str.3 = [23 x i8] c"The i2c port is open.\0A\00"
@.str.4 = [20 x i8] c"Reseting device...\0A\00"
@.str.5 = [26 x i8] c"ERROR: Device not reset.\0A\00"
@.str.6 = [36 x i8] c"Device is reset and ready for use.\0A\00"
@.str.7 = [30 x i8] c"ERROR: setting pwm frequency\0A\00"
@.str.8 = [25 x i8] c"Frequency set to %f Hz.\0A\00"
@.str.9 = [11 x i8] c"Pulse %d:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = call i32 @resetDev(i32 %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %31
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
store float 6.000000e+01, float* %3
%32 = load i32, i32* %2
%33 = load float, float* %3
%34 = call i32 @pwmFreq(i32 %32, float %33)
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %42
38: ; preds = %31
%39 = load float, float* %3
%40 = fpext float %39 to double
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %40)
br label %42
42: ; preds = %38, %36
store i32 150, i32* %4
store i32 600, i32* %5
store i32 0, i32* %6
store i32 1, i32* %7
store i32 0, i32* %11
br label %43
43: ; preds = %87, %42
%44 = load i32, i32* %7
%45 = icmp sle i32 %44, 10
br i1 %45, label %46, label %91
46: ; preds = %43
%47 = load i32, i32* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 %47)
store i32 0, i32* %8
br label %49
49: ; preds = %79, %46
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 8
br i1 %51, label %52, label %82
52: ; preds = %49
%53 = load i32, i32* %8
%54 = mul nsw i32 2, %53
store i32 %54, i32* %9
%55 = load i32, i32* %8
%56 = mul nsw i32 2, %55
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %52
%61 = load i32, i32* %2
%62 = load i32, i32* %9
%63 = load i32, i32* %4
%64 = call i32 @pwmPulse(i32 %61, i32 %62, i32 0, i32 %63)
%65 = load i32, i32* %2
%66 = load i32, i32* %10
%67 = load i32, i32* %5
%68 = call i32 @pwmPulse(i32 %65, i32 %66, i32 0, i32 %67)
br label %78
69: ; preds = %52
%70 = load i32, i32* %2
%71 = load i32, i32* %9
%72 = load i32, i32* %5
%73 = call i32 @pwmPulse(i32 %70, i32 %71, i32 0, i32 %72)
%74 = load i32, i32* %2
%75 = load i32, i32* %10
%76 = load i32, i32* %4
%77 = call i32 @pwmPulse(i32 %74, i32 %75, i32 0, i32 %76)
br label %78
78: ; preds = %69, %60
br label %79
79: ; preds = %78
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %49
82: ; preds = %49
%83 = load i32, i32* %6
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %82
store i32 1, i32* %6
br label %87
86: ; preds = %82
store i32 0, i32* %6
br label %87
87: ; preds = %86, %85
%88 = call i32 @usleep(i32 1000000)
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %43
91: ; preds = %43
%92 = load i32, i32* %2
%93 = call i32 @resetDev(i32 %92)
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-3\00"
@O_RDWR = global i32 0
@.str.8 = [25 x i8] c"Frequency set to %f Hz.\0A\00"
@.str.9 = [11 x i8] c"Pulse %d:\0A\00"
@str = [20 x i8] c"Opening i2c port...\00"
@str.10 = [22 x i8] c"The i2c port is open.\00"
@str.11 = [19 x i8] c"Reseting device...\00"
@str.12 = [35 x i8] c"Device is reset and ready for use.\00"
@str.13 = [29 x i8] c"ERROR: setting pwm frequency\00"
@str.14 = [25 x i8] c"ERROR: Device not reset.\00"
@str.15 = [24 x i8] c"ERROR opening i2c port.\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %2, 3
%5 = select i1 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @resetDev(i32 %2)
%9 = icmp eq i32 %8, 1
%10 = select i1 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call i32 @pwmFreq(i32 %2, float 6.000000e+01)
%13 = icmp eq i32 %12, 1
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.13, i64 0, i64 0))
br label %18
16: ; preds = %0
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double 6.000000e+01)
br label %18
18: ; preds = %16, %14
br label %19
19: ; preds = %18, %19
%20 = phi i32 [ %56, %19 ], [ 0, %18 ]
%21 = phi i32 [ %58, %19 ], [ 1, %18 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %20, 0
%24 = select i1 %23, i32 150, i32 600
%25 = select i1 %23, i32 600, i32 150
%26 = tail call i32 @pwmPulse(i32 %2, i32 0, i32 0, i32 %24)
%27 = tail call i32 @pwmPulse(i32 %2, i32 1, i32 0, i32 %25)
%28 = select i1 %23, i32 150, i32 600
%29 = select i1 %23, i32 600, i32 150
%30 = tail call i32 @pwmPulse(i32 %2, i32 2, i32 0, i32 %28)
%31 = tail call i32 @pwmPulse(i32 %2, i32 3, i32 0, i32 %29)
%32 = select i1 %23, i32 150, i32 600
%33 = select i1 %23, i32 600, i32 150
%34 = tail call i32 @pwmPulse(i32 %2, i32 4, i32 0, i32 %32)
%35 = tail call i32 @pwmPulse(i32 %2, i32 5, i32 0, i32 %33)
%36 = select i1 %23, i32 150, i32 600
%37 = select i1 %23, i32 600, i32 150
%38 = tail call i32 @pwmPulse(i32 %2, i32 6, i32 0, i32 %36)
%39 = tail call i32 @pwmPulse(i32 %2, i32 7, i32 0, i32 %37)
%40 = select i1 %23, i32 150, i32 600
%41 = select i1 %23, i32 600, i32 150
%42 = tail call i32 @pwmPulse(i32 %2, i32 8, i32 0, i32 %40)
%43 = tail call i32 @pwmPulse(i32 %2, i32 9, i32 0, i32 %41)
%44 = select i1 %23, i32 150, i32 600
%45 = select i1 %23, i32 600, i32 150
%46 = tail call i32 @pwmPulse(i32 %2, i32 10, i32 0, i32 %44)
%47 = tail call i32 @pwmPulse(i32 %2, i32 11, i32 0, i32 %45)
%48 = select i1 %23, i32 150, i32 600
%49 = select i1 %23, i32 600, i32 150
%50 = tail call i32 @pwmPulse(i32 %2, i32 12, i32 0, i32 %48)
%51 = tail call i32 @pwmPulse(i32 %2, i32 13, i32 0, i32 %49)
%52 = select i1 %23, i32 150, i32 600
%53 = select i1 %23, i32 600, i32 150
%54 = tail call i32 @pwmPulse(i32 %2, i32 14, i32 0, i32 %52)
%55 = tail call i32 @pwmPulse(i32 %2, i32 15, i32 0, i32 %53)
%56 = xor i32 %20, 1
%57 = tail call i32 @usleep(i32 1000000)
%58 = add nuw nsw i32 %21, 1
%59 = icmp eq i32 %58, 11
br i1 %59, label %60, label %19
60: ; preds = %19
%61 = tail call i32 @resetDev(i32 %2)
ret i32 0
}