#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void getstr(char *prompt, char *defaultAnswer, char *answer) {
  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, sizeof(answer), stdin))
    ;
  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    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe9a(%rip),%rdi
call   1050 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,-0xf0(%rbp)
jne    119b <getstr+0x5b>
lea    -0xf0(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xf0(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xf1(%rbp)
je     11d1 <getstr+0x91>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
setne  %al
mov    %al,-0xf1(%rbp)
mov    -0xf1(%rbp),%al
test   $0x1,%al
jne    11e4 <getstr+0xa4>
jmp    11f5 <getstr+0xb5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <getstr+0x66>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1222 <getstr+0xe2>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1201 <getstr+0xc1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125b <getstr+0x11b>
jmp    125b <getstr+0x11b>
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    12bb <getstr+0x17b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xf0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd6f(%rip),%rdi
call   1050 <printf@plt>
jmp    12d2 <getstr+0x192>
lea    -0xf0(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd5d(%rip),%rdi
call   1050 <printf@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstr>:
push   %r15
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,(%rsp)
jne    1187 <getstr+0x47>
lea    0xe9a(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0x1(%rsp),%rax
nopl   0x0(%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)
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
cmpb   $0x0,(%r15)
je     11f2 <getstr+0xb2>
lea    0xe3a(%rip),%rdi
jmp    1204 <getstr+0xc4>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe1c(%rip),%rdi
mov    %rsp,%rsi
mov    %r15,%rdx
call   1050 <printf@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %r15
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) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [200 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %3
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %3
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
store i8* %22, i8** %7
br label %23
23: ; preds = %35, %21
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 40
br label %33
33: ; preds = %28, %23
%34 = phi i1 [ false, %23 ], [ %32, %28 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %7
br label %23
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %7
br label %41
41: ; preds = %46, %38
%42 = load i8*, i8** %7
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 32
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 -1
store i8* %48, i8** %7
br label %41
49: ; preds = %41
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
store i8 0, i8* %51
%52 = load i8*, i8** %6
%53 = load i32, i32* @stdin
%54 = call i64 @fgets(i8* %52, i32 8, i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %49
br label %57
57: ; preds = %56, %49
%58 = load i8*, i8** %6
%59 = load i8*, i8** %6
%60 = call i32 @strlen(i8* %59)
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %58, i64 %62
store i8 0, i8* %63
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %57
%70 = load i8*, i8** %6
%71 = load i8*, i8** %5
%72 = call i32 @strcpy(i8* %70, i8* %71)
%73 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%74 = load i8*, i8** %6
%75 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %73, i8* %74)
br label %80
76: ; preds = %57
%77 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%78 = load i8*, i8** %6
%79 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %77, i8* %78)
br label %80
80: ; preds = %76, %69
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) {
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
br label %13
13: ; preds = %12, %17
%14 = phi i8* [ %18, %17 ], [ %5, %12 ]
%15 = load i8, i8* %14
switch i8 %15, label %17 [
i8 0, label %16
i8 40, label %16
]
16: ; preds = %13, %13
br label %19
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %14, i64 1
br label %13
19: ; preds = %16, %19
%20 = phi i8* [ %21, %19 ], [ %14, %16 ]
%21 = getelementptr inbounds i8, i8* %20, i64 -1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 32
br i1 %23, label %19, label %24
24: ; preds = %19
store i8 0, i8* %20
%25 = load i32, i32* @stdin
%26 = call i64 @fgets(i8* %2, i32 8, i32 %25)
%27 = call i32 @strlen(i8* %2)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %2, i64 %29
store i8 0, i8* %30
%31 = load i8, i8* %2
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 @strcpy(i8* %2, i8* %1)
br label %35
35: ; preds = %24, %33
%36 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %33 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %24 ]
%37 = call i32 @printf(i8* %36, i8* %5, i8* %2)
ret void
}