#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
void getstr(const char *prompt, const char *defaultAnswer, char *answer,
            int answerBufSize) {
  char *p, s[200];
  printf("%s (defaultAnswer = %s):", prompt, defaultAnswer);
  strcpy(s, prompt);
  if (!(*s))
    strcpy(s, "input:");
  p = s;
  while (*p && *p != '(')
    p++;
  p--;
  while (*p == ' ')
    p--;
  *(++p) = '\0';
  if (fgets(answer, answerBufSize - 1, stdin) == NULL)
    answer[0] = '\0';
  else
    answer[strlen(answer) - 1] = '\0';
  if (answer[0] == '\0') {
    strcpy(answer, defaultAnswer);
    printf("\t%s = %s\n", s, answer);
  } else {
    printf("\t%s set to %s\n", s, answer);
  }
}


x86 assembly (clang, -O0):
<getstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,-0xf0(%rbp)
jne    119e <getstr+0x5e>
lea    -0xf0(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xf0(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xf1(%rbp)
je     11d4 <getstr+0x94>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
setne  %al
mov    %al,-0xf1(%rbp)
mov    -0xf1(%rbp),%al
test   $0x1,%al
jne    11e7 <getstr+0xa7>
jmp    11f8 <getstr+0xb8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a9 <getstr+0x69>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1225 <getstr+0xe5>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1204 <getstr+0xc4>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1266 <getstr+0x126>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    128d <getstr+0x14d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x100(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12c6 <getstr+0x186>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xf0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd64(%rip),%rdi
call   1050 <printf@plt>
jmp    12dd <getstr+0x19d>
lea    -0xf0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xea0(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,(%rsp)
jne    118b <getstr+0x4b>
lea    0xe96(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0x1(%rsp),%rax
movzbl -0x1(%rax),%ecx
cmp    $0x28,%cl
je     11b0 <getstr+0x70>
test   %cl,%cl
je     11b0 <getstr+0x70>
add    $0x1,%rax
jmp    1190 <getstr+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x20,-0x2(%rax)
lea    -0x1(%rax),%rax
je     11b0 <getstr+0x70>
movb   $0x0,(%rax)
add    $0xffffffff,%r15d
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11f7 <getstr+0xb7>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
cmpb   $0x0,(%rbx)
je     11fa <getstr+0xba>
lea    0xe35(%rip),%rdi
jmp    120c <getstr+0xcc>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe14(%rip),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"%s (defaultAnswer = %s):\00"
@.str.1 = [7 x i8] c"input:\00"
@stdin = global i32 0
@.str.2 = [10 x i8] c"\09%s = %s\0A\00"
@.str.3 = [15 x i8] c"\09%s set to %s\0A\00"
define void @getstr(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [200 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %4
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
store i8* %24, i8** %9
br label %25
25: ; preds = %37, %23
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 40
br label %35
35: ; preds = %30, %25
%36 = phi i1 [ false, %25 ], [ %34, %30 ]
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %9
br label %25
40: ; preds = %35
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %9
br label %43
43: ; preds = %48, %40
%44 = load i8*, i8** %9
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 32
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i32 -1
store i8* %50, i8** %9
br label %43
51: ; preds = %43
%52 = load i8*, i8** %9
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %9
store i8 0, i8* %53
%54 = load i8*, i8** %7
%55 = load i32, i32* %8
%56 = sub nsw i32 %55, 1
%57 = load i32, i32* @stdin
%58 = call i32* @fgets(i8* %54, i32 %56, i32 %57)
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %51
%61 = load i8*, i8** %7
%62 = getelementptr inbounds i8, i8* %61, i64 0
store i8 0, i8* %62
br label %70
63: ; preds = %51
%64 = load i8*, i8** %7
%65 = load i8*, i8** %7
%66 = call i32 @strlen(i8* %65)
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %63, %60
%71 = load i8*, i8** %7
%72 = getelementptr inbounds i8, i8* %71, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %70
%77 = load i8*, i8** %7
%78 = load i8*, i8** %6
%79 = call i32 @strcpy(i8* %77, i8* %78)
%80 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%81 = load i8*, i8** %7
%82 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %80, i8* %81)
br label %87
83: ; preds = %70
%84 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%85 = load i8*, i8** %7
%86 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %84, i8* %85)
br label %87
87: ; preds = %83, %76
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"%s (defaultAnswer = %s):\00"
@.str.1 = [7 x i8] c"input:\00"
@stdin = global i32 0
@.str.2 = [10 x i8] c"\09%s = %s\0A\00"
@.str.3 = [15 x i8] c"\09%s set to %s\0A\00"
define void @getstr(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = call i32 @strcpy(i8* %6, i8* %0)
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
br label %14
14: ; preds = %13, %18
%15 = phi i8* [ %19, %18 ], [ %6, %13 ]
%16 = load i8, i8* %15
switch i8 %16, label %18 [
i8 0, label %17
i8 40, label %17
]
17: ; preds = %14, %14
br label %20
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %15, i64 1
br label %14
20: ; preds = %17, %20
%21 = phi i8* [ %22, %20 ], [ %15, %17 ]
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 32
br i1 %24, label %20, label %25
25: ; preds = %20
store i8 0, i8* %21
%26 = add nsw i32 %3, -1
%27 = load i32, i32* @stdin
%28 = call i32* @fgets(i8* %2, i32 %26, i32 %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %31
30: ; preds = %25
store i8 0, i8* %2
br label %38
31: ; preds = %25
%32 = call i32 @strlen(i8* %2)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %2, i64 %34
store i8 0, i8* %35
%36 = load i8, i8* %2
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30, %31
%39 = call i32 @strcpy(i8* %2, i8* %1)
br label %40
40: ; preds = %31, %38
%41 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %38 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %31 ]
%42 = call i32 @printf(i8* %41, i8* %6, i8* %2)
ret void
}