#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
bool get_character(bool print_prompt) {
  int ch;
  if (print_prompt) {
    printf("Enter a character: ");
    ch = getchar();
    putchar('\n');
  } else {
    ch = getchar();
  }
  if (ch == EOF) {
    printf("<EOF>\n\n");
    return false;
  } else {
    printf("Character: '%c'\n", ch);
    printf("Hex: %02x\n", ch);
    printf("Decimal: %d\n", ch);
    printf("Octal: %03o\n\n", ch);
    return true;
  }
}


x86 assembly (clang, -O0):
<get_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116c <get_character+0x3c>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1176 <get_character+0x46>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
jne    11a2 <get_character+0x72>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ed <get_character+0xbd>
mov    -0xc(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_character>:
push   %rbx
test   %edi,%edi
je     1168 <get_character+0x28>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1171 <get_character+0x31>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
mov    0x2e70(%rip),%rax
cmp    (%rax),%ebx
jne    118c <get_character+0x4c>
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter a character: \00"
@EOF = global i32 0
@.str.1 = [8 x i8] c"<EOF>\0A\0A\00"
@.str.2 = [17 x i8] c"Character: '%c'\0A\00"
@.str.3 = [11 x i8] c"Hex: %02x\0A\00"
@.str.4 = [13 x i8] c"Decimal: %d\0A\00"
@.str.5 = [14 x i8] c"Octal: %03o\0A\0A\00"
define i32 @get_character(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @getchar()
store i32 %9, i32* %4
%10 = call i32 @putchar(i8 signext 10)
br label %13
11: ; preds = %1
%12 = call i32 (...) @getchar()
store i32 %12, i32* %4
br label %13
13: ; preds = %11, %7
%14 = load i32, i32* %4
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %28
19: ; preds = %13
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %26)
store i32 1, i32* %2
br label %28
28: ; preds = %19, %17
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter a character: \00"
@EOF = global i32 0
@.str.2 = [17 x i8] c"Character: '%c'\0A\00"
@.str.3 = [11 x i8] c"Hex: %02x\0A\00"
@.str.4 = [13 x i8] c"Decimal: %d\0A\00"
@.str.5 = [14 x i8] c"Octal: %03o\0A\0A\00"
@str = [7 x i8] c"<EOF>\0A\00"
define i32 @get_character(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @getchar()
%6 = tail call i32 @putchar(i8 signext 10)
br label %9
7: ; preds = %1
%8 = tail call i32 (...) @getchar()
br label %9
9: ; preds = %7, %3
%10 = phi i32 [ %5, %3 ], [ %8, %7 ]
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %20
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %20
20: ; preds = %15, %13
%21 = phi i32 [ 0, %13 ], [ 1, %15 ]
ret i32 %21
}