#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 /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  setvbuf(stdout, NULL, _IONBF, 0);
  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(60, 0x40);
  output_enable();
  while (1) {
    set_pwm(1, 0, 250, 0x40);
    usleep(500000);
    set_pwm(1, 0, 400, 0x40);
    usleep(500000);
    set_pwm(1, 0, 500, 0x40);
    usleep(500000);
  }
  (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    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%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,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f3 <main+0x83>
cmpl   $0x1,-0x14(%rbp)
jne    11d5 <main+0x65>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x14(%rbp)
jne    11eb <main+0x7b>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    $0x3c,%edi
mov    $0x40,%esi
call   1070 <set_pwm_freq@plt>
mov    $0x0,%al
call   1060 <output_enable@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0xfa,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x190,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x1f4,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
jmp    1209 <main+0x99>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
mov    $0x40,%edi
mov    $0x1,%esi
call   1080 <servopi_init@plt>
test   %eax,%eax
je     11bd <main+0x4d>
cmp    $0x1,%eax
je     1242 <main+0xd2>
cmp    $0x2,%eax
jne    124e <main+0xde>
lea    0xe60(%rip),%rdi
jmp    1249 <main+0xd9>
mov    $0x3c,%edi
mov    $0x40,%esi
call   1070 <set_pwm_freq@plt>
xor    %eax,%eax
call   1060 <output_enable@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
xor    %esi,%esi
mov    $0xfa,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x190,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x1f4,%edx
mov    $0x40,%ecx
call   1040 <set_pwm@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
jmp    11e0 <main+0x70>
lea    0xdb7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @stdout
%8 = load i32, i32* @_IONBF
%9 = call i32 @setvbuf(i32 %7, i32* null, i32 %8, i32 0)
%10 = call i32 @servopi_init(i32 64, i32 1)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret i32 0
24: ; preds = %2
%25 = call i32 @set_pwm_freq(i32 60, i32 64)
%26 = call i32 (...) @output_enable()
br label %27
27: ; preds = %24, %27
%28 = call i32 @set_pwm(i32 1, i32 0, i32 250, i32 64)
%29 = call i32 @usleep(i32 500000)
%30 = call i32 @set_pwm(i32 1, i32 0, i32 400, i32 64)
%31 = call i32 @usleep(i32 500000)
%32 = call i32 @set_pwm(i32 1, i32 0, i32 500, i32 64)
%33 = call i32 @usleep(i32 500000)
br label %27
}

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 60, i32 64)
%14 = tail call i32 (...) @output_enable()
br label %15
15: ; preds = %15, %12
%16 = tail call i32 @set_pwm(i32 1, i32 0, i32 250, i32 64)
%17 = tail call i32 @usleep(i32 500000)
%18 = tail call i32 @set_pwm(i32 1, i32 0, i32 400, i32 64)
%19 = tail call i32 @usleep(i32 500000)
%20 = tail call i32 @set_pwm(i32 1, i32 0, i32 500, i32 64)
%21 = tail call i32 @usleep(i32 500000)
br label %15
}