#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*/ printf(char *, ...);
int /*<<< orphan*/ pwm_close(int, int);
int /*<<< orphan*/ pwm_get_duty_cycle(int, int, int *);
int /*<<< orphan*/ pwm_get_period(int, int, int *);
int /*<<< orphan*/ pwm_open(int, int);
int /*<<< orphan*/ pwm_set_duty_cycle(int, int, int);
int /*<<< orphan*/ pwm_set_enabled(int, int, int);
int /*<<< orphan*/ pwm_set_period(int, int, int);
int /*<<< orphan*/ usleep(int);
int iotbus_pwm_test() {
  int device = 0, channel = 0;
  int period = 1 * 1000;
  int duty_cycle = 1 * 1000 / 100;
  int set_duty_cycle;
  int get_period, get_duty_cycle;
  printf("<<< iotbus_pwm_test >>>\n");
  pwm_open(device, channel);
  pwm_set_period(device, channel, period);
  pwm_set_duty_cycle(device, channel, duty_cycle);
  pwm_set_enabled(device, channel, 1);
  while (1) {
    for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) {
      pwm_set_duty_cycle(device, channel, set_duty_cycle);
      pwm_get_period(device, channel, &get_period);
      pwm_get_duty_cycle(device, channel, &get_duty_cycle);
      printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle);
      usleep(500000);
    }
    for (set_duty_cycle = 0; set_duty_cycle < period; set_duty_cycle += 50) {
      pwm_set_duty_cycle(device, channel, set_duty_cycle);
      pwm_get_period(device, channel, &get_period);
      pwm_get_duty_cycle(device, channel, &get_duty_cycle);
      printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle);
      usleep(500000);
    }
  }
  pwm_close(device, channel);
  return 0;
}


x86 assembly (clang, -O0):
<iotbus_pwm_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
movl   $0xa,-0x10(%rbp)
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <pwm_open@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <pwm_set_period@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <pwm_set_duty_cycle@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x1,%edx
call   1080 <pwm_set_enabled@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1251 <iotbus_pwm_test+0xd1>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1090 <pwm_set_duty_cycle@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <pwm_get_period@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1070 <pwm_get_duty_cycle@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    -0x14(%rbp),%eax
sub    $0x32,%eax
mov    %eax,-0x14(%rbp)
jmp    11ef <iotbus_pwm_test+0x6f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12bc <iotbus_pwm_test+0x13c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1090 <pwm_set_duty_cycle@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <pwm_get_period@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1070 <pwm_get_duty_cycle@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x32,%eax
mov    %eax,-0x14(%rbp)
jmp    1258 <iotbus_pwm_test+0xd8>
jmp    11e9 <iotbus_pwm_test+0x69>

x86 assembly (clang, -O2):
<iotbus_pwm_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <pwm_open@plt>
mov    $0x3e8,%r12d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1070 <pwm_set_period@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <pwm_set_duty_cycle@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1090 <pwm_set_enabled@plt>
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xe0e(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
xor    %esi,%esi
mov    %r12d,%edx
call   10a0 <pwm_set_duty_cycle@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <pwm_get_period@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   1080 <pwm_get_duty_cycle@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
lea    -0x32(%r12),%eax
cmp    $0x32,%r12d
mov    %eax,%r12d
ja     1200 <iotbus_pwm_test+0x70>
mov    $0xffffffce,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x32,%ebp
xor    %edi,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   10a0 <pwm_set_duty_cycle@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <pwm_get_period@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   1080 <pwm_get_duty_cycle@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
cmp    $0x3b6,%ebp
jb     1260 <iotbus_pwm_test+0xd0>
mov    $0x3e8,%r12d
jmp    1200 <iotbus_pwm_test+0x70>

LLVM IR (-O0):
@.str = [25 x i8] c"<<< iotbus_pwm_test >>>\0A\00"
@.str.1 = [28 x i8] c"period(%d), duty_cycle(%d)\0A\00"
define i32 @iotbus_pwm_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1000, i32* %3
store i32 10, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = call i32 @pwm_open(i32 %9, i32 %10)
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @pwm_set_period(i32 %12, i32 %13, i32 %14)
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = call i32 @pwm_set_duty_cycle(i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = call i32 @pwm_set_enabled(i32 %20, i32 %21, i32 1)
br label %23
23: ; preds = %0, %69
%24 = load i32, i32* %3
store i32 %24, i32* %5
br label %25
25: ; preds = %43, %23
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i32, i32* %1
%30 = load i32, i32* %2
%31 = load i32, i32* %5
%32 = call i32 @pwm_set_duty_cycle(i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* %1
%34 = load i32, i32* %2
%35 = call i32 @pwm_get_period(i32 %33, i32 %34, i32* %6)
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = call i32 @pwm_get_duty_cycle(i32 %36, i32 %37, i32* %7)
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %40)
%42 = call i32 @usleep(i32 500000)
br label %43
43: ; preds = %28
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 50
store i32 %45, i32* %5
br label %25
46: ; preds = %25
store i32 0, i32* %5
br label %47
47: ; preds = %66, %46
%48 = load i32, i32* %5
%49 = load i32, i32* %3
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %69
51: ; preds = %47
%52 = load i32, i32* %1
%53 = load i32, i32* %2
%54 = load i32, i32* %5
%55 = call i32 @pwm_set_duty_cycle(i32 %52, i32 %53, i32 %54)
%56 = load i32, i32* %1
%57 = load i32, i32* %2
%58 = call i32 @pwm_get_period(i32 %56, i32 %57, i32* %6)
%59 = load i32, i32* %1
%60 = load i32, i32* %2
%61 = call i32 @pwm_get_duty_cycle(i32 %59, i32 %60, i32* %7)
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %62, i32 %63)
%65 = call i32 @usleep(i32 500000)
br label %66
66: ; preds = %51
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 50
store i32 %68, i32* %5
br label %47
69: ; preds = %47
br label %23
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"period(%d), duty_cycle(%d)\0A\00"
@str = [24 x i8] c"<<< iotbus_pwm_test >>>\00"
define i32 @iotbus_pwm_test() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @pwm_open(i32 0, i32 0)
%7 = tail call i32 @pwm_set_period(i32 0, i32 0, i32 1000)
%8 = tail call i32 @pwm_set_duty_cycle(i32 0, i32 0, i32 10)
%9 = tail call i32 @pwm_set_enabled(i32 0, i32 0, i32 1)
br label %10
10: ; preds = %21, %0
%11 = phi i32 [ 1000, %0 ], [ %22, %21 ]
%12 = call i32 @pwm_set_duty_cycle(i32 0, i32 0, i32 %11)
%13 = call i32 @pwm_get_period(i32 0, i32 0, i32* %1)
%14 = call i32 @pwm_get_duty_cycle(i32 0, i32 0, i32* %2)
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = call i32 @usleep(i32 500000)
%19 = add nsw i32 %11, -50
%20 = icmp ugt i32 %11, 50
br i1 %20, label %21, label %23
21: ; preds = %23, %10
%22 = phi i32 [ %19, %10 ], [ 1000, %23 ]
br label %10
23: ; preds = %10, %23
%24 = phi i32 [ %32, %23 ], [ 0, %10 ]
%25 = call i32 @pwm_set_duty_cycle(i32 0, i32 0, i32 %24)
%26 = call i32 @pwm_get_period(i32 0, i32 0, i32* %1)
%27 = call i32 @pwm_get_duty_cycle(i32 0, i32 0, i32* %2)
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29)
%31 = call i32 @usleep(i32 500000)
%32 = add nuw nsw i32 %24, 50
%33 = icmp ult i32 %24, 950
br i1 %33, label %23, label %21
}