#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 */
unsigned char getc();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(unsigned char);
int /*<<< orphan*/ pwm_set(unsigned int);
int /*<<< orphan*/ pwm_start();
int /*<<< orphan*/ pwm_stop();
void pwm_menu(void) {
  unsigned char c;
  static unsigned int cnt = 5;
  unsigned int duty;
  while (1) {
    printf("********PWM TEST MENU********\n\r");
    printf("[+] increase the PWM duty\n\r");
    printf("[-] decrease the PWM duty\n\r");
    printf("[S] stop the PWM\n\r");
    printf("[Q] quit\n\r");
    do {
      c = getc();
      if (c == '\n' || c == '\r') {
        printf("\n\r");
      } else {
        putc(c);
      }
    } while (c == '\n' || c == '\r');
    switch (c) {
    case '+': {
      duty = 100 / cnt;
      printf("duty = %d\n\r", duty);
      pwm_set(duty);
      cnt += 5;
      if (cnt > 100)
        cnt = 100;
      pwm_start();
      break;
    }
    case '-': {
      duty = 100 / cnt;
      printf("duty = %d\n\r", duty);
      pwm_set(duty);
      cnt -= 5;
      if (cnt < 5)
        cnt = 5;
      pwm_start();
      break;
    }
    case 's':
    case 'S': {
      pwm_stop();
      break;
    }
    case 'q':
    case 'Q': {
      return;
      break;
    }
    }
  }
}


x86 assembly (clang, -O0):
<pwm_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <getc@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0xa,%eax
je     11d2 <pwm_menu+0x72>
movzbl -0x1(%rbp),%eax
cmp    $0xd,%eax
jne    11e5 <pwm_menu+0x85>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ee <pwm_menu+0x8e>
movzbl -0x1(%rbp),%edi
call   1040 <putc@plt>
jmp    11f3 <pwm_menu+0x93>
movzbl -0x1(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x9(%rbp)
je     1212 <pwm_menu+0xb2>
movzbl -0x1(%rbp),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11ae <pwm_menu+0x4e>
movzbl -0x1(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x2b,%eax
je     1287 <pwm_menu+0x127>
jmp    1232 <pwm_menu+0xd2>
mov    -0x10(%rbp),%eax
sub    $0x2d,%eax
je     12e2 <pwm_menu+0x182>
jmp    1243 <pwm_menu+0xe3>
mov    -0x10(%rbp),%eax
sub    $0x51,%eax
je     1349 <pwm_menu+0x1e9>
jmp    1254 <pwm_menu+0xf4>
mov    -0x10(%rbp),%eax
sub    $0x53,%eax
je     133d <pwm_menu+0x1dd>
jmp    1265 <pwm_menu+0x105>
mov    -0x10(%rbp),%eax
sub    $0x71,%eax
je     1349 <pwm_menu+0x1e9>
jmp    1276 <pwm_menu+0x116>
mov    -0x10(%rbp),%eax
sub    $0x73,%eax
je     133d <pwm_menu+0x1dd>
jmp    134f <pwm_menu+0x1ef>
mov    $0x64,%eax
xor    %edx,%edx
divl   0x2dbc(%rip)
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <pwm_set@plt>
mov    0x2d9a(%rip),%eax
add    $0x5,%eax
mov    %eax,0x2d91(%rip)
cmpl   $0x64,0x2d8a(%rip)
jbe    12d6 <pwm_menu+0x176>
movl   $0x64,0x2d7a(%rip)
mov    $0x0,%al
call   1050 <pwm_start@plt>
jmp    134f <pwm_menu+0x1ef>
mov    $0x64,%eax
xor    %edx,%edx
divl   0x2d61(%rip)
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <pwm_set@plt>
mov    0x2d3f(%rip),%eax
sub    $0x5,%eax
mov    %eax,0x2d36(%rip)
cmpl   $0x5,0x2d2f(%rip)
jae    1331 <pwm_menu+0x1d1>
movl   $0x5,0x2d1f(%rip)
mov    $0x0,%al
call   1050 <pwm_start@plt>
jmp    134f <pwm_menu+0x1ef>
mov    $0x0,%al
call   1070 <pwm_stop@plt>
jmp    134f <pwm_menu+0x1ef>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1168 <pwm_menu+0x8>

x86 assembly (clang, -O2):
<pwm_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xfaa(%rip),%rbx
lea    0x100e(%rip),%r15
lea    0xfb9(%rip),%rbp
lea    0xf09(%rip),%r12
lea    0xe72(%rip),%r13
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf9d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xfab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xfb9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <getc@plt>
mov    %eax,%r14d
cmp    $0xd,%al
je     11e4 <pwm_menu+0x84>
cmp    $0xa,%r14b
jne    11f0 <pwm_menu+0x90>
mov    %rbp,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f9 <pwm_menu+0x99>
movzbl %r14b,%edi
call   1040 <putc@plt>
lea    -0xa(%r14),%eax
cmp    $0x23,%al
ja     1250 <pwm_menu+0xf0>
movzbl %al,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    $0x64,%eax
xor    %edx,%edx
divl   0x2e35(%rip)
mov    %rbx,%r14
mov    %eax,%ebx
lea    0xf6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rbx
call   1060 <pwm_set@plt>
mov    0x2e10(%rip),%eax
add    $0x5,%eax
cmp    $0x64,%eax
mov    $0x64,%ecx
cmovae %ecx,%eax
jmp    12b7 <pwm_menu+0x157>
add    $0xaf,%r14b
cmp    $0x22,%r14b
ja     118e <pwm_menu+0x2e>
movzbl %r14b,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1070 <pwm_stop@plt>
jmp    118e <pwm_menu+0x2e>
mov    $0x64,%eax
xor    %edx,%edx
divl   0x2dcc(%rip)
mov    %rbx,%r14
mov    %eax,%ebx
lea    0xf02(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rbx
call   1060 <pwm_set@plt>
mov    0x2da7(%rip),%eax
add    $0xfffffffb,%eax
cmp    $0x6,%eax
mov    $0x5,%ecx
cmovb  %ecx,%eax
mov    %eax,0x2d93(%rip)
xor    %eax,%eax
call   1050 <pwm_start@plt>
jmp    118e <pwm_menu+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@pwm_menu.cnt = internal global i32 5
@.str = [32 x i8] c"********PWM TEST MENU********\0A\0D\00"
@.str.1 = [28 x i8] c"[+] increase the PWM duty\0A\0D\00"
@.str.2 = [28 x i8] c"[-] decrease the PWM duty\0A\0D\00"
@.str.3 = [19 x i8] c"[S] stop the PWM\0A\0D\00"
@.str.4 = [11 x i8] c"[Q] quit\0A\0D\00"
@.str.5 = [3 x i8] c"\0A\0D\00"
@.str.6 = [12 x i8] c"duty = %d\0A\0D\00"
define void @pwm_menu() {
%1 = alloca i8
%2 = alloca i32
br label %3
3: ; preds = %0, %68
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %9
9: ; preds = %32, %3
%10 = call zeroext i8 (...) @getc()
store i8 %10, i8* %1
%11 = load i8, i8* %1
%12 = zext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8, i8* %1
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 13
br i1 %17, label %18, label %20
18: ; preds = %14, %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %23
20: ; preds = %14
%21 = load i8, i8* %1
%22 = call i32 @putc(i8 zeroext %21)
br label %23
23: ; preds = %20, %18
br label %24
24: ; preds = %23
%25 = load i8, i8* %1
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8, i8* %1
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 13
br label %32
32: ; preds = %28, %24
%33 = phi i1 [ true, %24 ], [ %31, %28 ]
br i1 %33, label %9, label %34
34: ; preds = %32
%35 = load i8, i8* %1
%36 = zext i8 %35 to i32
switch i32 %36, label %68 [
i32 43, label %37
i32 45, label %51
i32 115, label %65
i32 83, label %65
i32 113, label %67
i32 81, label %67
]
37: ; preds = %34
%38 = load i32, i32* @pwm_menu.cnt
%39 = udiv i32 100, %38
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %2
%43 = call i32 @pwm_set(i32 %42)
%44 = load i32, i32* @pwm_menu.cnt
%45 = add i32 %44, 5
store i32 %45, i32* @pwm_menu.cnt
%46 = load i32, i32* @pwm_menu.cnt
%47 = icmp ugt i32 %46, 100
br i1 %47, label %48, label %49
48: ; preds = %37
store i32 100, i32* @pwm_menu.cnt
br label %49
49: ; preds = %48, %37
%50 = call i32 (...) @pwm_start()
br label %68
51: ; preds = %34
%52 = load i32, i32* @pwm_menu.cnt
%53 = udiv i32 100, %52
store i32 %53, i32* %2
%54 = load i32, i32* %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %2
%57 = call i32 @pwm_set(i32 %56)
%58 = load i32, i32* @pwm_menu.cnt
%59 = sub i32 %58, 5
store i32 %59, i32* @pwm_menu.cnt
%60 = load i32, i32* @pwm_menu.cnt
%61 = icmp ult i32 %60, 5
br i1 %61, label %62, label %63
62: ; preds = %51
store i32 5, i32* @pwm_menu.cnt
br label %63
63: ; preds = %62, %51
%64 = call i32 (...) @pwm_start()
br label %68
65: ; preds = %34, %34
%66 = call i32 (...) @pwm_stop()
br label %68
67: ; preds = %34, %34
ret void
68: ; preds = %34, %65, %63, %49
br label %3
}

LLVM IR (-O2):
@pwm_menu.cnt = internal unnamed_addr global i32 5
@.str = [32 x i8] c"********PWM TEST MENU********\0A\0D\00"
@.str.1 = [28 x i8] c"[+] increase the PWM duty\0A\0D\00"
@.str.2 = [28 x i8] c"[-] decrease the PWM duty\0A\0D\00"
@.str.3 = [19 x i8] c"[S] stop the PWM\0A\0D\00"
@.str.4 = [11 x i8] c"[Q] quit\0A\0D\00"
@.str.5 = [3 x i8] c"\0A\0D\00"
@.str.6 = [12 x i8] c"duty = %d\0A\0D\00"
define void @pwm_menu() {
br label %1
1: ; preds = %37, %0
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %7
7: ; preds = %14, %1
%8 = tail call zeroext i8 (...) @getc()
switch i8 %8, label %11 [
i8 13, label %9
i8 10, label %9
]
9: ; preds = %7, %7
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %13
11: ; preds = %7
%12 = tail call i32 @putc(i8 zeroext %8)
br label %13
13: ; preds = %9, %11
switch i8 %8, label %37 [
i8 13, label %14
i8 10, label %14
i8 43, label %15
i8 45, label %25
i8 115, label %35
i8 83, label %35
i8 113, label %38
i8 81, label %38
]
14: ; preds = %13, %13
br label %7
15: ; preds = %13
%16 = load i32, i32* @pwm_menu.cnt
%17 = udiv i32 100, %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%19 = tail call i32 @pwm_set(i32 %17)
%20 = load i32, i32* @pwm_menu.cnt
%21 = add i32 %20, 5
%22 = icmp ult i32 %21, 100
%23 = select i1 %22, i32 %21, i32 100
store i32 %23, i32* @pwm_menu.cnt
%24 = tail call i32 (...) @pwm_start()
br label %37
25: ; preds = %13
%26 = load i32, i32* @pwm_menu.cnt
%27 = udiv i32 100, %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = tail call i32 @pwm_set(i32 %27)
%30 = load i32, i32* @pwm_menu.cnt
%31 = add i32 %30, -5
%32 = icmp ugt i32 %31, 5
%33 = select i1 %32, i32 %31, i32 5
store i32 %33, i32* @pwm_menu.cnt
%34 = tail call i32 (...) @pwm_start()
br label %37
35: ; preds = %13, %13
%36 = tail call i32 (...) @pwm_stop()
br label %37
37: ; preds = %13, %35, %25, %15
br label %1
38: ; preds = %13, %13
ret void
}