#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 */
struct sched_param {
  int __sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ gpioDirection(int, int);
int /*<<< orphan*/ gpioSet(int, int /*<<< orphan*/);
int /*<<< orphan*/ gpioSetup();
int /*<<< orphan*/ gpio_reserve(int);
int /*<<< orphan*/ gpio_set_direction(int, int /*<<< orphan*/);
int /*<<< orphan*/ gpio_set_state(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ usleep(int);
int pwm_test() {
  struct sched_param prio_struct;
  int ret;
  prio_struct.__sched_priority = 99;
  ret = sched_setscheduler(0, SCHED_FIFO, &prio_struct);
  if (ret) {
    printf("\n*** Warning ***\n");
    perror("Could not set real time priority");
    printf("This may reduce timing benchmark accuracy. ");
    printf("Try running as super user (sudo).\n\n");
  }
  gpioSetup();
  printf("Set up gpio ports\r\n");
  gpioDirection(23, 1);
  printf("GPIO is set to output\r\n");
  gpioSet(23, 0);
  printf("GPIO port 23 is low\r\n");
  gpio_reserve(23);
  gpio_set_direction(23, 0);
  while (1 == 1) {
    for (int i = 0; i < 200; ++i) {
      gpio_set_state(23, 1);
      usleep(900);
      gpio_set_state(23, 0);
      usleep(20000);
    }
    printf("Servo LEFT\r\n");
    for (int i = 0; i < 200; ++i) {
      gpio_set_state(23, 1);
      usleep(1400);
      gpio_set_state(23, 0);
      usleep(20000);
    }
    printf("Servo MIDDLE\r\n");
    sleep(2);
    for (int i = 0; i < 200; ++i) {
      gpio_set_state(23, 1);
      usleep(2400);
      gpio_set_state(23, 0);
      usleep(20000);
    }
    printf("Servo RIGHT\r\n");
  };
  return 0;
}


x86 assembly (clang, -O0):
<pwm_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x63,-0x8(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1070 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1210 <pwm_test+0x60>
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
lea    0xe1f(%rip),%rdi
call   1090 <perror@plt>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <gpioSetup@plt>
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
mov    $0x17,%edi
mov    $0x1,%esi
call   10d0 <gpioDirection@plt>
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1040 <gpioSet@plt>
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x17,%edi
call   1080 <gpio_reserve@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   10a0 <gpio_set_direction@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0xc8,-0x10(%rbp)
jge    12bd <pwm_test+0x10d>
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x384,%edi
call   10c0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10c0 <usleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1273 <pwm_test+0xc3>
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc8,-0x14(%rbp)
jge    131a <pwm_test+0x16a>
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x578,%edi
call   10c0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10c0 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12d0 <pwm_test+0x120>
lea    0xdb1(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xc8,-0x18(%rbp)
jge    1381 <pwm_test+0x1d1>
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x960,%edi
call   10c0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1337 <pwm_test+0x187>
lea    0xd59(%rip),%rdi
call   1050 <printf@plt>
jmp    126c <pwm_test+0xbc>

x86 assembly (clang, -O2):
<pwm_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x63,(%rsp)
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %rsp,%rdx
xor    %edi,%edi
call   1080 <sched_setscheduler@plt>
test   %eax,%eax
jne    1343 <pwm_test+0x183>
xor    %eax,%eax
call   1070 <gpioSetup@plt>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
mov    $0x17,%edi
mov    $0x1,%esi
call   10e0 <gpioDirection@plt>
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1050 <gpioSet@plt>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x17,%edi
call   1090 <gpio_reserve@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   10b0 <gpio_set_direction@plt>
lea    0xe3e(%rip),%r14
lea    0xe43(%rip),%r15
lea    0xe4a(%rip),%rbx
nopl   0x0(%rax)
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x384,%edi
call   10d0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10d0 <usleep@plt>
add    $0x1,%ebp
cmp    $0xc8,%ebp
jne    1260 <pwm_test+0xa0>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0xc8,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x578,%edi
call   10d0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10d0 <usleep@plt>
add    $0xffffffff,%ebp
jne    12b0 <pwm_test+0xf0>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    $0xc8,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x17,%edi
mov    $0x1,%esi
call   1030 <gpio_set_state@plt>
mov    $0x960,%edi
call   10d0 <usleep@plt>
mov    $0x17,%edi
xor    %esi,%esi
call   1030 <gpio_set_state@plt>
mov    $0x4e20,%edi
call   10d0 <usleep@plt>
add    $0xffffffff,%ebp
jne    1300 <pwm_test+0x140>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    1260 <pwm_test+0xa0>
lea    0xd69(%rip),%rdi
call   1040 <puts@plt>
lea    0xcaa(%rip),%rdi
call   10a0 <perror@plt>
lea    0xcbf(%rip),%rdi
call   1060 <printf@plt>
lea    0xd56(%rip),%rdi
call   1040 <puts@plt>
jmp    11eb <pwm_test+0x2b>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [18 x i8] c"\0A*** Warning ***\0A\00"
@.str.1 = [33 x i8] c"Could not set real time priority\00"
@.str.2 = [44 x i8] c"This may reduce timing benchmark accuracy. \00"
@.str.3 = [36 x i8] c"Try running as super user (sudo).\0A\0A\00"
@.str.4 = [20 x i8] c"Set up gpio ports\0D\0A\00"
@.str.5 = [24 x i8] c"GPIO is set to output\0D\0A\00"
@.str.6 = [22 x i8] c"GPIO port 23 is low\0D\0A\00"
@.str.7 = [13 x i8] c"Servo LEFT\0D\0A\00"
@.str.8 = [15 x i8] c"Servo MIDDLE\0D\0A\00"
@.str.9 = [14 x i8] c"Servo RIGHT\0D\0A\00"
define i32 @pwm_test() {
%1 = alloca %struct.sched_param
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i32 0, i32 0
store i32 99, i32* %6
%7 = load i32, i32* @SCHED_FIFO
%8 = call i32 @sched_setscheduler(i32 0, i32 %7, %struct.sched_param* %1)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %11, %0
%17 = call i32 (...) @gpioSetup()
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @gpioDirection(i32 23, i32 1)
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @gpioSet(i32 23, i32 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @gpio_reserve(i32 23)
%24 = call i32 @gpio_set_direction(i32 23, i32 0)
br label %25
25: ; preds = %16, %64
store i32 0, i32* %3
br label %26
26: ; preds = %34, %25
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 200
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = call i32 @gpio_set_state(i32 23, i32 1)
%31 = call i32 @usleep(i32 900)
%32 = call i32 @gpio_set_state(i32 23, i32 0)
%33 = call i32 @usleep(i32 20000)
br label %34
34: ; preds = %29
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %26
37: ; preds = %26
%38 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %47, %37
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 200
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = call i32 @gpio_set_state(i32 23, i32 1)
%44 = call i32 @usleep(i32 1400)
%45 = call i32 @gpio_set_state(i32 23, i32 0)
%46 = call i32 @usleep(i32 20000)
br label %47
47: ; preds = %42
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %39
50: ; preds = %39
%51 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%52 = call i32 @sleep(i32 2)
store i32 0, i32* %5
br label %53
53: ; preds = %61, %50
%54 = load i32, i32* %5
%55 = icmp slt i32 %54, 200
br i1 %55, label %56, label %64
56: ; preds = %53
%57 = call i32 @gpio_set_state(i32 23, i32 1)
%58 = call i32 @usleep(i32 2400)
%59 = call i32 @gpio_set_state(i32 23, i32 0)
%60 = call i32 @usleep(i32 20000)
br label %61
61: ; preds = %56
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %53
64: ; preds = %53
%65 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %25
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str.1 = [33 x i8] c"Could not set real time priority\00"
@.str.2 = [44 x i8] c"This may reduce timing benchmark accuracy. \00"
@str = [19 x i8] c"Set up gpio ports\0D\00"
@str.10 = [23 x i8] c"GPIO is set to output\0D\00"
@str.11 = [21 x i8] c"GPIO port 23 is low\0D\00"
@str.12 = [12 x i8] c"Servo LEFT\0D\00"
@str.13 = [14 x i8] c"Servo MIDDLE\0D\00"
@str.14 = [13 x i8] c"Servo RIGHT\0D\00"
@str.15 = [17 x i8] c"\0A*** Warning ***\00"
@str.16 = [35 x i8] c"Try running as super user (sudo).\0A\00"
define i32 @pwm_test() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 99, i32* %3
%4 = load i32, i32* @SCHED_FIFO
%5 = call i32 @sched_setscheduler(i32 0, i32 %4, %struct.sched_param* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.15, i64 0, i64 0))
%9 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.16, i64 0, i64 0))
br label %12
12: ; preds = %7, %0
%13 = call i32 (...) @gpioSetup()
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%15 = call i32 @gpioDirection(i32 23, i32 1)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%17 = call i32 @gpioSet(i32 23, i32 0)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%19 = call i32 @gpio_reserve(i32 23)
%20 = call i32 @gpio_set_direction(i32 23, i32 0)
br label %23
21: ; preds = %23
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
br label %36
23: ; preds = %31, %12
%24 = phi i32 [ 0, %12 ], [ %32, %31 ]
%25 = call i32 @gpio_set_state(i32 23, i32 1)
%26 = call i32 @usleep(i32 900)
%27 = call i32 @gpio_set_state(i32 23, i32 0)
%28 = call i32 @usleep(i32 20000)
%29 = add nuw nsw i32 %24, 1
%30 = icmp eq i32 %29, 200
br i1 %30, label %21, label %31
31: ; preds = %23, %44
%32 = phi i32 [ %29, %23 ], [ 0, %44 ]
br label %23
33: ; preds = %36
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0))
%35 = call i32 @sleep(i32 2)
br label %46
36: ; preds = %21, %36
%37 = phi i32 [ 0, %21 ], [ %42, %36 ]
%38 = call i32 @gpio_set_state(i32 23, i32 1)
%39 = call i32 @usleep(i32 1400)
%40 = call i32 @gpio_set_state(i32 23, i32 0)
%41 = call i32 @usleep(i32 20000)
%42 = add nuw nsw i32 %37, 1
%43 = icmp eq i32 %42, 200
br i1 %43, label %33, label %36
44: ; preds = %46
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0))
br label %31
46: ; preds = %33, %46
%47 = phi i32 [ 0, %33 ], [ %52, %46 ]
%48 = call i32 @gpio_set_state(i32 23, i32 1)
%49 = call i32 @usleep(i32 2400)
%50 = call i32 @gpio_set_state(i32 23, i32 0)
%51 = call i32 @usleep(i32 20000)
%52 = add nuw nsw i32 %47, 1
%53 = icmp eq i32 %52, 200
br i1 %53, label %44, label %46
}