#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*/ SetupCfg(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
void IOSetup() {
  char opt;
  do {
    system("clear");
    printf(" __________________________________________ \n");
    printf("|                  Menu                    |\n");
    printf("|______ABElectronics IOPi - IO Setup_______|\n");
    printf("|                                          |\n");
    printf("|   1. Change Polarity                     |\n");
    printf("|   2. Change Pull-Ups                     |\n");
    printf("|   3. Change Direction                    |\n");
    printf("|   4. Change Interrupts                    |\n");
    printf("|   0. Back                                |\n");
    printf("|__________________________________________|\n");
    printf("|__________________________________________|\n");
    printf("\n");
    printf("Choose an option: ");
    do {
      fflush(stdin);
      opt = getc(stdin);
    } while (opt < '0' || opt > '4');
    system("clear");
    switch (opt) {
    case '0':
      return;
    case '1':
      SetupCfg(3);
      break;
    case '2':
      SetupCfg(2);
      break;
    case '3':
      SetupCfg(1);
      break;
    case '4':
      SetupCfg(4);
      break;
    }
  } while (1);
}


x86 assembly (clang, -O0):
<IOSetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb5(%rip),%rdi
call   1030 <system@plt>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
lea    0xef3(%rip),%rdi
call   1040 <printf@plt>
lea    0xf15(%rip),%rdi
call   1040 <printf@plt>
lea    0xf37(%rip),%rdi
call   1040 <printf@plt>
lea    0xf59(%rip),%rdi
call   1040 <printf@plt>
lea    0xf7b(%rip),%rdi
call   1040 <printf@plt>
lea    0xf9d(%rip),%rdi
call   1040 <printf@plt>
lea    0xfc0(%rip),%rdi
call   1040 <printf@plt>
lea    0xfe2(%rip),%rdi
call   1040 <printf@plt>
lea    0xfd6(%rip),%rdi
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
lea    0xfec(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x2(%rbp)
jl     123e <IOSetup+0xee>
movsbl -0x1(%rbp),%eax
cmp    $0x34,%eax
setg   %al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
test   $0x1,%al
jne    1200 <IOSetup+0xb0>
lea    0xdc4(%rip),%rdi
call   1030 <system@plt>
movsbl -0x1(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     12bb <IOSetup+0x16b>
mov    -0x10(%rbp),%rax
lea    0xd8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    12cf <IOSetup+0x17f>
mov    $0x3,%edi
call   1060 <SetupCfg@plt>
jmp    12bb <IOSetup+0x16b>
mov    $0x2,%edi
call   1060 <SetupCfg@plt>
jmp    12bb <IOSetup+0x16b>
mov    $0x1,%edi
call   1060 <SetupCfg@plt>
jmp    12bb <IOSetup+0x16b>
mov    $0x4,%edi
call   1060 <SetupCfg@plt>
jmp    12c0 <IOSetup+0x170>
mov    $0x1,%al
test   $0x1,%al
jne    1158 <IOSetup+0x8>
jmp    12cf <IOSetup+0x17f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IOSetup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe92(%rip),%rbx
lea    0x103a(%rip),%rbp
lea    0xe8a(%rip),%r14
mov    0x2e51(%rip),%r12
lea    0xe62(%rip),%r13
jmp    11aa <IOSetup+0x3a>
mov    $0x4,%edi
call   1080 <SetupCfg@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf19(%rip),%rdi
call   1040 <puts@plt>
lea    0xf3a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf5b(%rip),%rdi
call   1040 <puts@plt>
lea    0xf7d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    (%r12),%edi
call   1090 <getc@plt>
mov    %eax,%r15d
lea    -0x35(%r15),%eax
cmp    $0xfb,%al
jb     1240 <IOSetup+0xd0>
mov    %rbx,%rdi
call   1050 <system@plt>
add    $0xd0,%r15b
cmp    $0x4,%r15b
ja     11aa <IOSetup+0x3a>
mov    $0x3,%edi
movzbl %r15b,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    $0x2,%edi
call   1080 <SetupCfg@plt>
jmp    11aa <IOSetup+0x3a>
mov    $0x1,%edi
call   1080 <SetupCfg@plt>
jmp    11aa <IOSetup+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [46 x i8] c" __________________________________________ \0A\00"
@.str.2 = [46 x i8] c"| Menu |\0A\00"
@.str.3 = [46 x i8] c"|______ABElectronics IOPi - IO Setup_______|\0A\00"
@.str.4 = [46 x i8] c"| |\0A\00"
@.str.5 = [46 x i8] c"| 1. Change Polarity |\0A\00"
@.str.6 = [46 x i8] c"| 2. Change Pull-Ups |\0A\00"
@.str.7 = [46 x i8] c"| 3. Change Direction |\0A\00"
@.str.8 = [47 x i8] c"| 4. Change Interrupts |\0A\00"
@.str.9 = [46 x i8] c"| 0. Back |\0A\00"
@.str.10 = [46 x i8] c"|__________________________________________|\0A\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [19 x i8] c"Choose an option: \00"
@stdin = global i32 0
define void @IOSetup() {
%1 = alloca i8
br label %2
2: ; preds = %46, %0
%3 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %17
17: ; preds = %30, %2
%18 = load i32, i32* @stdin
%19 = call i32 @fflush(i32 %18)
%20 = load i32, i32* @stdin
%21 = call signext i8 @getc(i32 %20)
store i8 %21, i8* %1
br label %22
22: ; preds = %17
%23 = load i8, i8* %1
%24 = sext i8 %23 to i32
%25 = icmp slt i32 %24, 48
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i8, i8* %1
%28 = sext i8 %27 to i32
%29 = icmp sgt i32 %28, 52
br label %30
30: ; preds = %26, %22
%31 = phi i1 [ true, %22 ], [ %29, %26 ]
br i1 %31, label %17, label %32
32: ; preds = %30
%33 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%34 = load i8, i8* %1
%35 = sext i8 %34 to i32
switch i32 %35, label %45 [
i32 48, label %36
i32 49, label %37
i32 50, label %39
i32 51, label %41
i32 52, label %43
]
36: ; preds = %32
br label %47
37: ; preds = %32
%38 = call i32 @SetupCfg(i32 3)
br label %45
39: ; preds = %32
%40 = call i32 @SetupCfg(i32 2)
br label %45
41: ; preds = %32
%42 = call i32 @SetupCfg(i32 1)
br label %45
43: ; preds = %32
%44 = call i32 @SetupCfg(i32 4)
br label %45
45: ; preds = %32, %43, %41, %39, %37
br label %46
46: ; preds = %45
br i1 true, label %2, label %47
47: ; preds = %36, %46
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.12 = [19 x i8] c"Choose an option: \00"
@stdin = global i32 0
@str = [45 x i8] c" __________________________________________ \00"
@str.13 = [45 x i8] c"| Menu |\00"
@str.14 = [45 x i8] c"|______ABElectronics IOPi - IO Setup_______|\00"
@str.15 = [45 x i8] c"| |\00"
@str.16 = [45 x i8] c"| 1. Change Polarity |\00"
@str.17 = [45 x i8] c"| 2. Change Pull-Ups |\00"
@str.18 = [45 x i8] c"| 3. Change Direction |\00"
@str.19 = [46 x i8] c"| 4. Change Interrupts |\00"
@str.20 = [45 x i8] c"| 0. Back |\00"
@str.22 = [45 x i8] c"|__________________________________________|\00"
define void @IOSetup() {
br label %1
1: ; preds = %32, %0
%2 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.13, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.14, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.15, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.16, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.17, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.18, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.19, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.20, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.22, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.22, i64 0, i64 0))
%14 = tail call i32 @putchar(i32 10)
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %16
16: ; preds = %16, %1
%17 = load i32, i32* @stdin
%18 = tail call i32 @fflush(i32 %17)
%19 = load i32, i32* @stdin
%20 = tail call signext i8 @getc(i32 %19)
%21 = add i8 %20, -53
%22 = icmp ult i8 %21, -5
br i1 %22, label %16, label %23
23: ; preds = %16
%24 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i8 %20, label %32 [
i8 48, label %25
i8 49, label %29
i8 50, label %26
i8 51, label %27
i8 52, label %28
]
25: ; preds = %23
ret void
26: ; preds = %23
br label %29
27: ; preds = %23
br label %29
28: ; preds = %23
br label %29
29: ; preds = %23, %28, %27, %26
%30 = phi i32 [ 2, %26 ], [ 1, %27 ], [ 4, %28 ], [ 3, %23 ]
%31 = tail call i32 @SetupCfg(i32 %30)
br label %32
32: ; preds = %29, %23
br label %1
}