#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*/ _IONBF;
int /*<<< orphan*/ output_enable();
int /*<<< orphan*/ printf(char *);
int servopi_init(int, int);
int /*<<< orphan*/ set_pwm(int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ set_pwm_freq(int, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  int x;
  int a;
  a = servopi_init(0x40, 1);
  if (a != 0) {
    if (a == 1) {
      printf("Error enabling GPIO Pin");
    }
    if (a == 2) {
      printf("Error setting GPIO Pin direction");
    }
    return (0);
  }
  set_pwm_freq(1000, 0x40);
  output_enable();
  while (1) {
    for (x = 1; x <= 4095; x = x + 5) {
      set_pwm(1, 0, x, 0x40);
    }
    for (x = 4095; x >= 0; x = x - 5) {
      set_pwm(1, 0, x, 0x40);
    }
  }
  (void)argc;
  (void)argv;
  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    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x40,%edi
mov    $0x1,%esi
call   1080 <servopi_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e3 <main+0x83>
cmpl   $0x1,-0x18(%rbp)
jne    11c5 <main+0x65>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x18(%rbp)
jne    11db <main+0x7b>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    $0x3e8,%edi
mov    $0x40,%esi
call   1070 <set_pwm_freq@plt>
mov    $0x0,%al
call   1060 <output_enable@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0xfff,-0x14(%rbp)
jg     122f <main+0xcf>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    -0x14(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x14(%rbp)
jmp    1200 <main+0xa0>
movl   $0xfff,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1262 <main+0x102>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    -0x14(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x14(%rbp)
jmp    1236 <main+0xd6>
jmp    11f9 <main+0x99>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x1,%ebx
mov    $0x40,%edi
mov    $0x1,%esi
call   1080 <servopi_init@plt>
test   %eax,%eax
je     11a9 <main+0x49>
cmp    $0x1,%eax
je     1212 <main+0xb2>
cmp    $0x2,%eax
jne    121e <main+0xbe>
lea    0xe71(%rip),%rdi
jmp    1219 <main+0xb9>
mov    $0x3e8,%edi
mov    $0x40,%esi
call   1070 <set_pwm_freq@plt>
xor    %eax,%eax
call   1060 <output_enable@plt>
nop
mov    $0x1,%edi
xor    %esi,%esi
mov    %ebx,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
lea    0x5(%rbx),%eax
cmp    $0xffb,%ebx
mov    %eax,%ebx
jb     11c0 <main+0x60>
mov    $0x1004,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xfffffffb,%ebp
mov    $0x1,%ebx
mov    $0x1,%edi
xor    %esi,%esi
mov    %ebp,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
cmp    $0x4,%ebp
ja     11f0 <main+0x90>
jmp    11c0 <main+0x60>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [24 x i8] c"Error enabling GPIO Pin\00"
@.str.1 = [33 x i8] c"Error setting GPIO Pin direction\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdout
%9 = load i32, i32* @_IONBF
%10 = call i32 @setvbuf(i32 %8, i32* null, i32 %9, i32 0)
%11 = call i32 @servopi_init(i32 64, i32 1)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
ret i32 0
25: ; preds = %2
%26 = call i32 @set_pwm_freq(i32 1000, i32 64)
%27 = call i32 (...) @output_enable()
br label %28
28: ; preds = %25, %48
store i32 1, i32* %6
br label %29
29: ; preds = %35, %28
%30 = load i32, i32* %6
%31 = icmp sle i32 %30, 4095
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %6
%34 = call i32 @set_pwm(i32 1, i32 0, i32 %33, i32 64)
br label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 5
store i32 %37, i32* %6
br label %29
38: ; preds = %29
store i32 4095, i32* %6
br label %39
39: ; preds = %45, %38
%40 = load i32, i32* %6
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* %6
%44 = call i32 @set_pwm(i32 1, i32 0, i32 %43, i32 64)
br label %45
45: ; preds = %42
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 5
store i32 %47, i32* %6
br label %39
48: ; preds = %39
br label %28
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [24 x i8] c"Error enabling GPIO Pin\00"
@.str.1 = [33 x i8] c"Error setting GPIO Pin direction\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IONBF
%5 = tail call i32 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = tail call i32 @servopi_init(i32 64, i32 1)
switch i32 %6, label %11 [
i32 0, label %12
i32 1, label %8
i32 2, label %7
]
7: ; preds = %2
br label %8
8: ; preds = %2, %7
%9 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = tail call i32 @printf(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %2
ret i32 0
12: ; preds = %2
%13 = tail call i32 @set_pwm_freq(i32 1000, i32 64)
%14 = tail call i32 (...) @output_enable()
br label %15
15: ; preds = %20, %12
%16 = phi i32 [ 1, %12 ], [ %21, %20 ]
%17 = tail call i32 @set_pwm(i32 1, i32 0, i32 %16, i32 64)
%18 = add nuw nsw i32 %16, 5
%19 = icmp ult i32 %16, 4091
br i1 %19, label %20, label %22
20: ; preds = %22, %15
%21 = phi i32 [ %18, %15 ], [ 1, %22 ]
br label %15
22: ; preds = %15, %22
%23 = phi i32 [ %25, %22 ], [ 4095, %15 ]
%24 = tail call i32 @set_pwm(i32 1, i32 0, i32 %23, i32 64)
%25 = add nsw i32 %23, -5
%26 = icmp ugt i32 %23, 4
br i1 %26, label %22, label %20
}