#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*/);
char getc(int /*<<< orphan*/);
int /*<<< orphan*/ iWritePin(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
void IOChange() {
  int pin;
  printf("Please choose the PIN (1-32): ");
  do {
    scanf("%d", &pin);
  } while (pin < 1 || pin > 32);
  char opt;
  printf("Please choose the Output Value (0 or 1): ");
  do {
    fflush(stdin);
    opt = getc(stdin);
  } while (opt < '0' || opt > '1');
  switch (opt) {
  case '0':
    if (iWritePin(pin, 0) == 0)
      printf("Write '0' to IO '%d' - with Success...\n", pin);
    else
      printf("Fail to write '0' to IO '%d'...\n", pin);
    break;
  case '1':
    if (iWritePin(pin, 1) == 0)
      printf("Write '1' to IO '%d' - with Success...\n", pin);
    else
      printf("Fail to write '1' to IO '%d'...\n", pin);
    break;
  }
  sleep(1);
}


x86 assembly (clang, -O0):
<IOChange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x6(%rbp)
jl     119f <IOChange+0x3f>
cmpl   $0x20,-0x4(%rbp)
setg   %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
test   $0x1,%al
jne    1176 <IOChange+0x16>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x7(%rbp)
jl     11f6 <IOChange+0x96>
movsbl -0x5(%rbp),%eax
cmp    $0x31,%eax
setg   %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
test   $0x1,%al
jne    11b8 <IOChange+0x58>
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x30,%eax
je     1227 <IOChange+0xc7>
jmp    1216 <IOChange+0xb6>
mov    -0xc(%rbp),%eax
sub    $0x31,%eax
je     1266 <IOChange+0x106>
jmp    12a8 <IOChange+0x148>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <iWritePin@plt>
cmp    $0x0,%eax
jne    1250 <IOChange+0xf0>
mov    -0x4(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <IOChange+0x101>
mov    -0x4(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a8 <IOChange+0x148>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1040 <iWritePin@plt>
cmp    $0x0,%eax
jne    1292 <IOChange+0x132>
mov    -0x4(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a3 <IOChange+0x143>
mov    -0x4(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a8 <IOChange+0x148>
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IOChange>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea6(%rip),%r14
lea    0x4(%rsp),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffdf,%eax
cmp    $0xffffffe0,%eax
jb     1180 <IOChange+0x20>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e3c(%rip),%rbx
nopl   0x0(%rax)
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    (%rbx),%edi
call   1080 <getc@plt>
lea    -0x32(%rax),%ecx
cmp    $0xfe,%cl
jb     11b0 <IOChange+0x50>
cmp    $0x31,%al
je     11ea <IOChange+0x8a>
cmp    $0x30,%al
jne    1220 <IOChange+0xc0>
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1040 <iWritePin@plt>
mov    0x4(%rsp),%esi
test   %eax,%eax
je     1209 <IOChange+0xa9>
lea    0xe8c(%rip),%rdi
jmp    1219 <IOChange+0xb9>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1040 <iWritePin@plt>
mov    0x4(%rsp),%esi
test   %eax,%eax
je     1212 <IOChange+0xb2>
lea    0xeb6(%rip),%rdi
jmp    1219 <IOChange+0xb9>
lea    0xe3c(%rip),%rdi
jmp    1219 <IOChange+0xb9>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Please choose the PIN (1-32): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [42 x i8] c"Please choose the Output Value (0 or 1): \00"
@stdin = global i32 0
@.str.3 = [40 x i8] c"Write '0' to IO '%d' - with Success...\0A\00"
@.str.4 = [33 x i8] c"Fail to write '0' to IO '%d'...\0A\00"
@.str.5 = [40 x i8] c"Write '1' to IO '%d' - with Success...\0A\00"
@.str.6 = [33 x i8] c"Fail to write '1' to IO '%d'...\0A\00"
define void @IOChange() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %12, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %6
6: ; preds = %4
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 32
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ true, %6 ], [ %11, %9 ]
br i1 %13, label %4, label %14
14: ; preds = %12
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %29, %14
%17 = load i32, i32* @stdin
%18 = call i32 @fflush(i32 %17)
%19 = load i32, i32* @stdin
%20 = call signext i8 @getc(i32 %19)
store i8 %20, i8* %2
br label %21
21: ; preds = %16
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = icmp slt i32 %23, 48
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = icmp sgt i32 %27, 49
br label %29
29: ; preds = %25, %21
%30 = phi i1 [ true, %21 ], [ %28, %25 ]
br i1 %30, label %16, label %31
31: ; preds = %29
%32 = load i8, i8* %2
%33 = sext i8 %32 to i32
switch i32 %33, label %56 [
i32 48, label %34
i32 49, label %45
]
34: ; preds = %31
%35 = load i32, i32* %1
%36 = call i32 @iWritePin(i32 %35, i32 0)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %1
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %44
41: ; preds = %34
%42 = load i32, i32* %1
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %38
br label %56
45: ; preds = %31
%46 = load i32, i32* %1
%47 = call i32 @iWritePin(i32 %46, i32 1)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* %1
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %55
52: ; preds = %45
%53 = load i32, i32* %1
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52, %49
br label %56
56: ; preds = %31, %55, %44
%57 = call i32 @sleep(i32 1)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Please choose the PIN (1-32): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [42 x i8] c"Please choose the Output Value (0 or 1): \00"
@stdin = global i32 0
@.str.3 = [40 x i8] c"Write '0' to IO '%d' - with Success...\0A\00"
@.str.4 = [33 x i8] c"Fail to write '0' to IO '%d'...\0A\00"
@.str.5 = [40 x i8] c"Write '1' to IO '%d' - with Success...\0A\00"
@.str.6 = [33 x i8] c"Fail to write '1' to IO '%d'...\0A\00"
define void @IOChange() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add i32 %6, -33
%8 = icmp ult i32 %7, -32
br i1 %8, label %4, label %9
9: ; preds = %4
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %11, %9
%12 = load i32, i32* @stdin
%13 = call i32 @fflush(i32 %12)
%14 = load i32, i32* @stdin
%15 = call signext i8 @getc(i32 %14)
%16 = add i8 %15, -50
%17 = icmp ult i8 %16, -2
br i1 %17, label %11, label %18
18: ; preds = %11
switch i8 %15, label %37 [
i8 48, label %19
i8 49, label %28
]
19: ; preds = %18
%20 = load i32, i32* %1
%21 = call i32 @iWritePin(i32 %20, i32 0)
%22 = icmp eq i32 %21, 0
%23 = load i32, i32* %1
br i1 %22, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %37
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %37
28: ; preds = %18
%29 = load i32, i32* %1
%30 = call i32 @iWritePin(i32 %29, i32 1)
%31 = icmp eq i32 %30, 0
%32 = load i32, i32* %1
br i1 %31, label %33, label %35
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %32)
br label %37
37: ; preds = %33, %35, %24, %26, %18
%38 = call i32 @sleep(i32 1)
ret void
}