#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*/);
char getchar();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
char inputCharacter(void) {
  char c, sentence[2];
  int i = 0;
  puts("Enter a character: ");
  while ((c = getchar()) != '\n')
    sentence[i++] = c;
  if (c == '\n')
    sentence[i++] = c;
  sentence[i] = '\0';
  if (strlen(sentence) > 0)
    c = sentence[0];
  else
    c = '\0';
  fflush(stdin);
  return c;
}


x86 assembly (clang, -O0):
<inputCharacter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     118a <inputCharacter+0x4a>
mov    -0x1(%rbp),%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0x3(%rbp,%rax,1)
jmp    115b <inputCharacter+0x1b>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    11ab <inputCharacter+0x6b>
mov    -0x1(%rbp),%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0x3(%rbp,%rax,1)
movslq -0x8(%rbp),%rax
movb   $0x0,-0x3(%rbp,%rax,1)
lea    -0x3(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11d2 <inputCharacter+0x92>
mov    -0x3(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11d6 <inputCharacter+0x96>
movb   $0x0,-0x1(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputCharacter>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x0,%ebx
cmp    $0xa,%al
je     1183 <inputCharacter+0x43>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,0x6(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1170 <inputCharacter+0x30>
mov    %ebx,%eax
movw   $0xa,0x6(%rsp,%rax,1)
lea    0x6(%rsp),%rdi
call   1040 <strlen@plt>
test   %rax,%rax
movzbl 0x6(%rsp),%eax
cmovg  %eax,%ebp
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"Enter a character: \00"
@stdin = global i32 0
define signext i8 @inputCharacter() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
br i1 %5, label %15, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %9, %6 ], [ 0, %0 ]
%8 = phi i8 [ %11, %6 ], [ %4, %0 ]
%9 = add nuw i64 %7, 1
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %7
store i8 %8, i8* %10
%11 = tail call signext i8 (...) @getchar()
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = trunc i64 %9 to i32
br label %15
15: ; preds = %13, %0
%16 = phi i32 [ 0, %0 ], [ %14, %13 ]
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %17
store i8 10, i8* %18
%19 = add nuw nsw i32 %16, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i64 @strlen(i8* %2)
%23 = icmp sgt i64 %22, 0
%24 = load i8, i8* %2
%25 = select i1 %23, i8 %24, i8 0
%26 = load i32, i32* @stdin
%27 = tail call i32 @fflush(i32 %26)
ret i8 %25
}