#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 */
typedef int /*<<< orphan*/ answer;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
const char *askuser(const char *dflt) {
  static char answer[256];
  char *p;
  if (feof(stdin) || ferror(stdin)) {
    (void)fprintf(stderr, "\n");
    exit(1);
  }
  for (;;) {
    if (dflt)
      (void)fprintf(stderr, "Terminal type? [%s] ", dflt);
    else
      (void)fprintf(stderr, "Terminal type? ");
    (void)fflush(stderr);
    if (fgets(answer, sizeof(answer), stdin) == NULL) {
      if (dflt == NULL) {
        (void)fprintf(stderr, "\n");
        exit(1);
      }
      return (dflt);
    }
    if ((p = strchr(answer, '\n')) != NULL)
      *p = '\0';
    if (answer[0])
      return (answer);
    if (dflt != NULL)
      return (dflt);
  }
}


x86 assembly (clang, -O0):
<askuser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    11ac <askuser+0x3c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11cd <askuser+0x5d>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11d2 <askuser+0x62>
cmpq   $0x0,-0x10(%rbp)
je     11fd <askuser+0x8d>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1214 <askuser+0xa4>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
lea    0x2e3e(%rip),%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    127f <askuser+0x10f>
cmpq   $0x0,-0x10(%rbp)
jne    1272 <askuser+0x102>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12df <askuser+0x16f>
lea    0x2dea(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a5 <askuser+0x135>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpb   $0x0,0x2dc4(%rip)
je     12c2 <askuser+0x152>
lea    0x2db7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12df <askuser+0x16f>
cmpq   $0x0,-0x10(%rbp)
je     12da <askuser+0x16a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12df <askuser+0x16f>
jmp    11d2 <askuser+0x62>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<askuser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e63(%rip),%r13
mov    0x0(%r13),%edi
call   1070 <feof@plt>
test   %rax,%rax
jne    1265 <askuser+0xf5>
mov    0x0(%r13),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1265 <askuser+0xf5>
test   %rbx,%rbx
setne  %r15b
mov    0x2e21(%rip),%rbp
lea    0x2eb2(%rip),%r14
xor    $0x1,%r15b
lea    0xe39(%rip),%r12
jmp    11e1 <askuser+0x71>
nopl   0x0(%rax,%rax,1)
movzbl 0x2e99(%rip),%eax
test   %al,%al
sete   %cl
test   %r15b,%cl
je     124d <askuser+0xdd>
mov    0x0(%rbp),%edi
test   %rbx,%rbx
je     1200 <askuser+0x90>
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    120e <askuser+0x9e>
nopl   0x0(%rax,%rax,1)
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1080 <fflush@plt>
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1243 <askuser+0xd3>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d0 <askuser+0x60>
movb   $0x0,(%rax)
jmp    11d0 <askuser+0x60>
test   %rbx,%rbx
jne    1253 <askuser+0xe3>
mov    0x0(%rbp),%edi
jmp    126e <askuser+0xfe>
test   %al,%al
cmovne %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@askuser.answer = internal global [256 x i8] zeroinitializer
@stdin = global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [21 x i8] c"Terminal type? [%s] \00"
@.str.2 = [16 x i8] c"Terminal type? \00"
define i8* @askuser(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i32, i32* @stdin
%6 = call i64 @feof(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @stdin
%10 = call i64 @ferror(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8, %1
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
br label %17
17: ; preds = %56, %16
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %27
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* @stderr
%29 = call i32 @fflush(i32 %28)
%30 = load i32, i32* @stdin
%31 = call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i32 256, i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %42
33: ; preds = %27
%34 = load i8*, i8** %3
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %33
%41 = load i8*, i8** %3
store i8* %41, i8** %2
br label %57
42: ; preds = %27
%43 = call i8* @strchr(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i8 signext 10)
store i8* %43, i8** %4
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = load i8*, i8** %4
store i8 0, i8* %46
br label %47
47: ; preds = %45, %42
%48 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0)
%49 = icmp ne i8 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i8** %2
br label %57
51: ; preds = %47
%52 = load i8*, i8** %3
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = load i8*, i8** %3
store i8* %55, i8** %2
br label %57
56: ; preds = %51
br label %17
57: ; preds = %54, %50, %40
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@askuser.answer = internal global [256 x i8] zeroinitializer
@stdin = global i32 0
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [21 x i8] c"Terminal type? [%s] \00"
@.str.2 = [16 x i8] c"Terminal type? \00"
define i8* @askuser(i8* %0) {
%2 = load i32, i32* @stdin
%3 = tail call i64 @feof(i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = load i32, i32* @stdin
%7 = tail call i64 @ferror(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = icmp eq i8* %0, null
%11 = xor i1 %10, true
br label %16
12: ; preds = %5, %1
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %37
%17 = load i32, i32* @stderr
br i1 %10, label %20, label %18
18: ; preds = %16
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
20: ; preds = %16
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @fflush(i32 %23)
%25 = load i32, i32* @stdin
%26 = tail call i32* @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i32 256, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %22
br i1 %10, label %29, label %43
29: ; preds = %28
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i8 signext 10)
%35 = icmp eq i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %33
store i8 0, i8* %34
br label %37
37: ; preds = %36, %33
%38 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0)
%39 = icmp ne i8 %38, 0
%40 = or i1 %39, %11
br i1 %40, label %41, label %16
41: ; preds = %37
%42 = select i1 %39, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @askuser.answer, i64 0, i64 0), i8* %0
br label %43
43: ; preds = %41, %28
%44 = phi i8* [ %0, %28 ], [ %42, %41 ]
ret i8* %44
}