#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 /*<<< orphan*/ scanf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strlen(char *);
char charInput() {
  char *buffer;
  char ans;
  int bytes;
  size_t read_size = 1;
  scanf(" ");
  buffer = (char *)malloc(read_size + 1);
  bytes = getline(&buffer, &read_size, stdin);
  if (buffer != NULL) {
    size_t length = strlen(buffer);
    if (length > 0 && buffer[length - 1] == '\n') {
      buffer[--length] = '\0';
    }
  }
  if (bytes != -1) {
    ans = buffer[0];
    free(buffer);
    return ans;
  } else {
    fputs("Something went wrong with charInput(). Please try again.", stderr);
    free(buffer);
    return '\0';
  }
}


x86 assembly (clang, -O0):
<charInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x1,-0x20(%rbp)
lea    0xe89(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ff <charInput+0x9f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11fa <charInput+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11fa <charInput+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    11ff <charInput+0x9f>
cmpl   $0xffffffff,-0x18(%rbp)
je     1226 <charInput+0xc6>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x11(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1248 <charInput+0xe8>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charInput>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movq   $0x1,0x10(%rsp)
lea    0xe8a(%rip),%rdi
call   1070 <scanf@plt>
mov    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <getline@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11c7 <charInput+0x67>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11c7 <charInput+0x67>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11c7 <charInput+0x67>
movb   $0x0,-0x1(%rbx,%rax,1)
cmp    $0xffffffff,%ebp
je     11da <charInput+0x7a>
mov    0x8(%rsp),%rdi
mov    (%rdi),%bl
call   1030 <free@plt>
jmp    11fb <charInput+0x9b>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   1050 <fputs@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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