#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char *mymalloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *asktype(char *def) {
  char *in = mymalloc(128);
  printf("Enter that type[%s]: ", def);
  fflush(stdout);
  fgets(in, 127, stdin);
  if (in[strlen(in) - 1] == '\n')
    in[strlen(in) - 1] = 0;
  if (!*in)
    strcpy(in, def);
  return in;
}


x86 assembly (clang, -O0):
<asktype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x80,%edi
call   1080 <mymalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    $0x7f,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11fa <asktype+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1214 <asktype+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asktype>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x80,%edi
call   1080 <mymalloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x7f,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11c7 <asktype+0x67>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
cmpb   $0x0,(%rbx)
jne    11d7 <asktype+0x77>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter that type[%s]: \00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @asktype(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i8* @mymalloc(i32 128)
store i8* %4, i8** %3
%5 = load i8*, i8** %2
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
%9 = load i8*, i8** %3
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 127, i32 %10)
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %28
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %21, %1
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = load i8*, i8** %2
%35 = call i32 @strcpy(i8* %33, i8* %34)
br label %36
36: ; preds = %32, %28
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter that type[%s]: \00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @asktype(i8* %0) {
%2 = tail call i8* @mymalloc(i32 128)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = load i32, i32* @stdin
%7 = tail call i32 @fgets(i8* %2, i32 127, i32 %6)
%8 = tail call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = tail call i32 @strlen(i8* %2)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %14, %1
%20 = load i8, i8* %2
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @strcpy(i8* %2, i8* %0)
br label %24
24: ; preds = %22, %19
ret i8* %2
}