#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*/ PrintTermTypeList();
int ReadChar();
int /*<<< orphan*/ SetTermType(int);
int String2TermType(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void AskTermType(int argc, char *argv[]) {
  int t = 0;
  int c;
  if (argc > 1 && strlen(argv[1]) == 1)
    t = argv[1][0] - '0';
  else if (argc > 1 && strlen(argv[1]) > 1)
    t = String2TermType(argv[1]);
  if (t <= 0 || t >= 9) {
    printf("Select a terminal type (or specify it on command line):\n");
    PrintTermTypeList();
    printf("\n>");
    do {
      c = ReadChar();
      t = c - '0';
    } while (t <= 0 || t >= 9);
    printf("%c\n", c);
  }
  SetTermType(t);
}


x86 assembly (clang, -O0):
<AskTermType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    11ac <AskTermType+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    11ac <AskTermType+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <AskTermType+0x81>
cmpl   $0x1,-0x4(%rbp)
jle    11dc <AskTermType+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jle    11dc <AskTermType+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <String2TermType@plt>
mov    %eax,-0x14(%rbp)
jmp    11e1 <AskTermType+0x81>
cmpl   $0x0,-0x14(%rbp)
jle    11f5 <AskTermType+0x95>
cmpl   $0x9,-0x14(%rbp)
jl     1260 <AskTermType+0x100>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <PrintTermTypeList@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <ReadChar@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    1244 <AskTermType+0xe4>
cmpl   $0x9,-0x14(%rbp)
setge  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1218 <AskTermType+0xb8>
mov    -0x18(%rbp),%esi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <SetTermType@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AskTermType>:
push   %rbx
cmp    $0x2,%edi
jl     11b0 <AskTermType+0x40>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
mov    0x8(%rbx),%rdi
cmp    $0x1,%eax
jne    1193 <AskTermType+0x23>
movsbl (%rdi),%ebx
add    $0xffffffd0,%ebx
jmp    11a8 <AskTermType+0x38>
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     11b0 <AskTermType+0x40>
mov    0x8(%rbx),%rdi
call   1030 <String2TermType@plt>
mov    %eax,%ebx
lea    -0x9(%rbx),%eax
cmp    $0xfffffff7,%eax
ja     1204 <AskTermType+0x94>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <PrintTermTypeList@plt>
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <ReadChar@plt>
lea    -0x39(%rax),%ecx
cmp    $0xfffffff8,%ecx
jb     11e0 <AskTermType+0x70>
mov    %eax,%ebx
add    $0xffffffd0,%ebx
lea    0xe08(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1050 <SetTermType@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"Select a terminal type (or specify it on command line):\0A\00"
@.str.1 = [3 x i8] c"\0A>\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define void @AskTermType(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 48
store i32 %22, i32* %5
br label %38
23: ; preds = %9, %2
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @String2TermType(i8* %35)
store i32 %36, i32* %5
br label %37
37: ; preds = %32, %26, %23
br label %38
38: ; preds = %37, %15
%39 = load i32, i32* %5
%40 = icmp sle i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %5
%43 = icmp sge i32 %42, 9
br i1 %43, label %44, label %63
44: ; preds = %41, %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%46 = call i32 (...) @PrintTermTypeList()
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %58, %44
%49 = call i32 (...) @ReadChar()
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = sub nsw i32 %50, 48
store i32 %51, i32* %5
br label %52
52: ; preds = %48
%53 = load i32, i32* %5
%54 = icmp sle i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = load i32, i32* %5
%57 = icmp sge i32 %56, 9
br label %58
58: ; preds = %55, %52
%59 = phi i1 [ true, %52 ], [ %57, %55 ]
br i1 %59, label %48, label %60
60: ; preds = %58
%61 = load i32, i32* %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %41
%64 = load i32, i32* %5
%65 = call i32 @SetTermType(i32 %64)
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"\0A>\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@str = [56 x i8] c"Select a terminal type (or specify it on command line):\00"
define void @AskTermType(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %24
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* %6)
%8 = icmp eq i32 %7, 1
%9 = load i8*, i8** %5
br i1 %8, label %10, label %14
10: ; preds = %4
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
%13 = add nsw i32 %12, -48
br label %20
14: ; preds = %4
%15 = tail call i32 @strlen(i8* %9)
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = tail call i32 @String2TermType(i8* %18)
br label %20
20: ; preds = %17, %10
%21 = phi i32 [ %13, %10 ], [ %19, %17 ]
%22 = add i32 %21, -9
%23 = icmp ult i32 %22, -8
br i1 %23, label %24, label %35
24: ; preds = %2, %14, %20
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 (...) @PrintTermTypeList()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %28, %24
%29 = tail call i32 (...) @ReadChar()
%30 = add i32 %29, -57
%31 = icmp ult i32 %30, -8
br i1 %31, label %28, label %32
32: ; preds = %28
%33 = add nsw i32 %29, -48
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %35
35: ; preds = %20, %32
%36 = phi i32 [ %33, %32 ], [ %21, %20 ]
%37 = tail call i32 @SetTermType(i32 %36)
ret void
}