#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 EXIT_SUCCESS;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getch();
scalar_t__ iscntrl(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stdout;
int main(void) {
  int ch;
  char vis[4];
  printf("Enter a character: ");
  fflush(stdout);
  ch = getch();
  snprintf(vis, sizeof vis, "%c", ch);
  if (iscntrl(ch))
    snprintf(vis, sizeof vis, "^%c", (ch & 0x7f) + '@');
  printf("\nYou entered: %02x (%s)\n", ch, vis);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x4,%esi
lea    0xe7d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
je     11cd <main+0x7d>
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%ecx
and    $0x7f,%ecx
add    $0x40,%ecx
mov    $0x4,%esi
lea    0xe4c(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%ebx
lea    0xe94(%rip),%rdx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
mov    %ebx,%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
je     11bc <main+0x6c>
mov    %ebx,%ecx
and    $0x7f,%ecx
add    $0x40,%ecx
lea    0xe67(%rip),%rdx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1050 <snprintf@plt>
lea    0xe55(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter a character: \00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c"^%c\00"
@.str.3 = [25 x i8] c"\0AYou entered: %02x (%s)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = call i32 (...) @getch()
store i32 %7, i32* %2
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @snprintf(i8* %8, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %2
%12 = call i64 @iscntrl(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* %2
%17 = and i32 %16, 127
%18 = add nsw i32 %17, 64
%19 = call i32 @snprintf(i8* %15, i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %14, %0
%21 = load i32, i32* %2
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter a character: \00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c"^%c\00"
@.str.3 = [25 x i8] c"\0AYou entered: %02x (%s)\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = tail call i32 (...) @getch()
%7 = call i32 @snprintf(i8* %2, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i64 @iscntrl(i32 %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = and i32 %6, 127
%12 = add nuw nsw i32 %11, 64
%13 = call i32 @snprintf(i8* %2, i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8* %2)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}