#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ set_only_pwm(int, unsigned long, unsigned long);
int /*<<< orphan*/ set_pwm(int, unsigned long, unsigned long);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stop_pwm(int);
void *strtol(char *, int /*<<< orphan*/ *, int);
void main(int argc, char *argv[]) {
  int duty_cycle;
  unsigned long period, Thigh;
  int pwm;
  char command;
  if (argc == 4) {
  } else {
    printf("Illegal arguments passed\n");
    return;
  }
  pwm = strtol(argv[1], NULL, 10);
  duty_cycle = strtol(argv[2], NULL, 10);
  period = strtol(argv[3], NULL, 10);
  Thigh = (period / 100) * duty_cycle;
  if (period = 0) {
    period = 21500000;
    Thigh = (period / 100) * duty_cycle;
  }
  printf("PWM channel sel : %d\n", pwm);
  printf("Calculated Thigh: %lu\n", Thigh);
  printf("Total Period    : %lu nSec\n", period);
  set_pwm(pwm, Thigh, period);
  while (1) {
    set_only_pwm(pwm, Thigh, period);
    scanf("%c", &command);
    printf("Command entered %x\n", command);
    switch (command) {
    case 0x44:
      Thigh -= 90000;
      break;
    case 0x43:
      Thigh += 90000;
      break;
    case 'L':
      Thigh = 360000;
      break;
    case 'R':
      Thigh = 1900000;
      break;
      set_only_pwm(pwm, Thigh, period);
      break;
    case 'x':
    case 'X':
      goto EXIT;
    default:
      printf("Unknown option\n\n");
    }
    fflush(stdin);
    command = 0;
  }
EXIT:
  stop_pwm(pwm);
  printf("pwm command and control complete. G'bye\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jne    118e <main+0x1e>
jmp    11a1 <main+0x31>
lea    0xf43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1361 <main+0x1f1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
movslq -0x14(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    121e <main+0xae>
jmp    1240 <main+0xd0>
movq   $0x1481060,-0x20(%rbp)
01
mov    -0x20(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
movslq -0x14(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <set_pwm@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <set_only_pwm@plt>
lea    0xe9f(%rip),%rdi
lea    -0x2d(%rbp),%rsi
call   1090 <scanf@plt>
movsbl -0x2d(%rbp),%esi
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl -0x2d(%rbp),%eax
add    $0xffffffbd,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x35,%eax
ja     1326 <main+0x1b6>
mov    -0x38(%rbp),%rax
lea    0xd28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rax
sub    $0x15f90,%rax
mov    %rax,-0x28(%rbp)
jmp    1334 <main+0x1c4>
mov    -0x28(%rbp),%rax
add    $0x15f90,%rax
mov    %rax,-0x28(%rbp)
jmp    1334 <main+0x1c4>
movq   $0x57e40,-0x28(%rbp)
jmp    1334 <main+0x1c4>
movq   $0x1cfde0,-0x28(%rbp)
jmp    1334 <main+0x1c4>
jmp    134b <main+0x1db>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
movb   $0x0,-0x2d(%rbp)
jmp    1285 <main+0x115>
mov    -0x2c(%rbp),%edi
call   1040 <stop_pwm@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x4,%edi
jne    12bf <main+0x13f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,%rbp
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
shr    $0x2,%rdx
movslq %ebp,%r12
imul   %rdx,%r12
lea    0xee8(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeed(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xef3(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1070 <set_pwm@plt>
lea    0xef5(%rip),%r13
mov    0x2db2(%rip),%rbp
lea    0xdc3(%rip),%r15
jmp    125e <main+0xde>
lea    0xf33(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rbx
mov    0x0(%rbp),%edi
call   1090 <fflush@plt>
movb   $0x0,0x7(%rsp)
mov    %rbx,%r12
mov    %r14d,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1030 <set_only_pwm@plt>
lea    0xeaf(%rip),%rdi
lea    0x7(%rsp),%rsi
call   10a0 <scanf@plt>
movsbl 0x7(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffbd,%eax
cmp    $0x35,%eax
ja     123f <main+0xbf>
mov    $0x57e40,%ebx
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0x15f90,%r12
jmp    124b <main+0xcb>
add    $0xfffffffffffea070,%r12
jmp    124b <main+0xcb>
mov    $0x1cfde0,%ebx
jmp    124e <main+0xce>
lea    0xe72(%rip),%rdi
jmp    1040 <puts@plt>
mov    %r14d,%edi
call   1050 <stop_pwm@plt>
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Illegal arguments passed\0A\00"
@.str.1 = [22 x i8] c"PWM channel sel : %d\0A\00"
@.str.2 = [23 x i8] c"Calculated Thigh: %lu\0A\00"
@.str.3 = [28 x i8] c"Total Period : %lu nSec\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [20 x i8] c"Command entered %x\0A\00"
@.str.6 = [17 x i8] c"Unknown option\0A\0A\00"
@stdin = global i32 0
@.str.7 = [41 x i8] c"pwm command and control complete. G'bye\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %13
12: ; preds = %2
br label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %82
15: ; preds = %12
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @strtol(i8* %18, i32* null, i32 10)
%20 = ptrtoint i8* %19 to i32
store i32 %20, i32* %8
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i8* @strtol(i8* %23, i32* null, i32 10)
%25 = ptrtoint i8* %24 to i32
store i32 %25, i32* %5
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i8* @strtol(i8* %28, i32* null, i32 10)
%30 = ptrtoint i8* %29 to i64
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = udiv i64 %31, 100
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = mul i64 %32, %34
store i64 %35, i64* %7
store i64 0, i64* %6
br i1 false, label %36, label %42
36: ; preds = %15
store i64 21500000, i64* %6
%37 = load i64, i64* %6
%38 = udiv i64 %37, 100
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = mul i64 %38, %40
store i64 %41, i64* %7
br label %42
42: ; preds = %36, %15
%43 = load i32, i32* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = load i64, i64* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i64 %45)
%47 = load i64, i64* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 %47)
%49 = load i32, i32* %8
%50 = load i64, i64* %7
%51 = load i64, i64* %6
%52 = call i32 @set_pwm(i32 %49, i64 %50, i64 %51)
br label %53
53: ; preds = %42, %75
%54 = load i32, i32* %8
%55 = load i64, i64* %7
%56 = load i64, i64* %6
%57 = call i32 @set_only_pwm(i32 %54, i64 %55, i64 %56)
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%59 = load i8, i8* %9
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = load i8, i8* %9
%63 = sext i8 %62 to i32
switch i32 %63, label %73 [
i32 68, label %64
i32 67, label %67
i32 76, label %70
i32 82, label %71
i32 120, label %72
i32 88, label %72
]
64: ; preds = %53
%65 = load i64, i64* %7
%66 = sub i64 %65, 90000
store i64 %66, i64* %7
br label %75
67: ; preds = %53
%68 = load i64, i64* %7
%69 = add i64 %68, 90000
store i64 %69, i64* %7
br label %75
70: ; preds = %53
store i64 360000, i64* %7
br label %75
71: ; preds = %53
store i64 1900000, i64* %7
br label %75
72: ; preds = %53, %53
br label %78
73: ; preds = %53
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %73, %71, %70, %67, %64
%76 = load i32, i32* @stdin
%77 = call i32 @fflush(i32 %76)
store i8 0, i8* %9
br label %53
78: ; preds = %72
%79 = load i32, i32* %8
%80 = call i32 @stop_pwm(i32 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %78, %13
ret void
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"PWM channel sel : %d\0A\00"
@.str.2 = [23 x i8] c"Calculated Thigh: %lu\0A\00"
@.str.3 = [28 x i8] c"Total Period : %lu nSec\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [20 x i8] c"Command entered %x\0A\00"
@stdin = global i32 0
@str = [25 x i8] c"Illegal arguments passed\00"
@str.8 = [40 x i8] c"pwm command and control complete. G'bye\00"
@str.9 = [16 x i8] c"Unknown option\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %52
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i8* @strtol(i8* nocapture %14, i32* null, i32 10)
%16 = ptrtoint i8* %15 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i8* @strtol(i8* nocapture %18, i32* null, i32 10)
%20 = ptrtoint i8* %19 to i64
%21 = udiv i64 %20, 100
%22 = shl i64 %16, 32
%23 = ashr exact i64 %22, 32
%24 = mul i64 %21, %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 0)
%28 = tail call i32 @set_pwm(i32 %12, i64 %24, i64 0)
br label %29
29: ; preds = %45, %7
%30 = phi i64 [ %24, %7 ], [ %46, %45 ]
%31 = call i32 @set_only_pwm(i32 %12, i64 %30, i64 0)
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
switch i32 %37, label %43 [
i32 68, label %38
i32 67, label %40
i32 76, label %45
i32 82, label %42
i32 120, label %49
i32 88, label %49
]
38: ; preds = %29
%39 = add i64 %30, -90000
br label %45
40: ; preds = %29
%41 = add i64 %30, 90000
br label %45
42: ; preds = %29
br label %45
43: ; preds = %29
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
br label %45
45: ; preds = %29, %43, %42, %40, %38
%46 = phi i64 [ %30, %43 ], [ 1900000, %42 ], [ %41, %40 ], [ %39, %38 ], [ 360000, %29 ]
%47 = load i32, i32* @stdin
%48 = call i32 @fflush(i32 %47)
store i8 0, i8* %3
br label %29
49: ; preds = %29, %29
%50 = call i32 @stop_pwm(i32 %12)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
br label %52
52: ; preds = %49, %5
ret void
}