#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int my_getpass(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strlen(char *);
char *stringInput(int turnOffEcho) {
  int bytes_read;
  size_t read_size = 1;
  char *username = (char *)malloc(read_size + 1);
  if (turnOffEcho == 1) {
    bytes_read = my_getpass(&username, &read_size, stdin);
    puts(" ");
  } else
    bytes_read = getline(&username, &read_size, stdin);
  if (username != NULL) {
    size_t len = strlen(username);
    if (len > 0 && username[len - 1] == '\n') {
      username[--len] = '\0';
    }
  }
  if (bytes_read != -1) {
    return (char *)username;
  } else {
    fputs("Something went wrong with stringInput(). Please try again.", stderr);
    free(username);
    return "";
  }
}


x86 assembly (clang, -O0):
<stringInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11c8 <stringInput+0x58>
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <my_getpass@plt>
mov    %eax,-0x10(%rbp)
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
jmp    11e1 <stringInput+0x71>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123a <stringInput+0xca>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    1235 <stringInput+0xc5>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1235 <stringInput+0xc5>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    123a <stringInput+0xca>
cmpl   $0xffffffff,-0x10(%rbp)
je     1251 <stringInput+0xe1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    127a <stringInput+0x10a>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    0xda1(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xd8b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringInput>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movq   $0x1,0x10(%rsp)
mov    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
cmp    $0x1,%ebx
jne    11bd <stringInput+0x4d>
call   1080 <my_getpass@plt>
mov    %eax,%ebp
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
jmp    11c4 <stringInput+0x54>
call   1090 <getline@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11e7 <stringInput+0x77>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11e7 <stringInput+0x77>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11e7 <stringInput+0x77>
movb   $0x0,-0x1(%rbx,%rax,1)
cmp    $0xffffffff,%ebp
je     11f3 <stringInput+0x83>
mov    0x8(%rsp),%rax
jmp    1219 <stringInput+0xa9>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
call   1060 <fputs@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xde8(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [59 x i8] c"Something went wrong with stringInput(). Please try again.\00"
@stderr = global i32 0
@.str.2 = [1 x i8] zeroinitializer
define i8* @stringInput(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %3
store i64 1, i64* %5
%8 = load i64, i64* %5
%9 = add i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stdin
%16 = call i32 @my_getpass(i8** %6, i64* %5, i32 %15)
store i32 %16, i32* %4
%17 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
18: ; preds = %1
%19 = load i32, i32* @stdin
%20 = call i32 @getline(i8** %6, i64* %5, i32 %19)
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %14
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = call i64 @strlen(i8* %25)
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = icmp ugt i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = sub i64 %31, 1
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i8*, i8** %6
%39 = load i64, i64* %7
%40 = add i64 %39, -1
store i64 %40, i64* %7
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %37, %29, %24
br label %43
43: ; preds = %42, %21
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i8*, i8** %6
store i8* %47, i8** %2
br label %53
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = call i32 @fputs(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = load i8*, i8** %6
%52 = call i32 @free(i8* %51)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %53
53: ; preds = %48, %46
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [59 x i8] c"Something went wrong with stringInput(). Please try again.\00"
@stderr = global i32 0
@.str.2 = [1 x i8] zeroinitializer
define i8* @stringInput(i32 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = bitcast i64* %2 to i8*
store i64 1, i64* %2
%5 = bitcast i8** %3 to i8*
%6 = tail call i64 @malloc(i64 2)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = icmp eq i32 %0, 1
%9 = load i32, i32* @stdin
br i1 %8, label %10, label %13
10: ; preds = %1
%11 = call i32 @my_getpass(i8** %3, i64* %2, i32 %9)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %1
%14 = call i32 @getline(i8** %3, i64* %2, i32 %9)
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %11, %10 ], [ %14, %13 ]
%17 = load i8*, i8** %3
%18 = icmp eq i8* %17, null
br i1 %18, label %28, label %19
19: ; preds = %15
%20 = call i64 @strlen(i8* %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = add i64 %20, -1
%24 = getelementptr inbounds i8, i8* %17, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %22
store i8 0, i8* %24
br label %28
28: ; preds = %19, %22, %27, %15
%29 = icmp eq i32 %16, -1
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = load i8*, i8** %3
br label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 @fputs(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %32, %30
%38 = phi i8* [ %31, %30 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %32 ]
ret i8* %38
}