#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 */
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int main01(void) {
  fputc('a', stdout);
  char ch;
  ch = fgetc(stdin);
  printf("ch = %c\n", ch);
  fputc(ch, stderr);
  printf("\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main01>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    $0x61,%edi
call   1060 <fputc@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1(%rbp),%al
mov    0x2e50(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main01>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    $0x61,%edi
call   1070 <fputc@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1060 <fgetc@plt>
movsbl %al,%ebx
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <fputc@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe63(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"ch = %c\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"pause\00"
define i32 @main01() {
%1 = alloca i8
%2 = load i32, i32* @stdout
%3 = call i32 @fputc(i8 signext 97, i32 %2)
%4 = load i32, i32* @stdin
%5 = call signext i8 @fgetc(i32 %4)
store i8 %5, i8* %1
%6 = load i8, i8* %1
%7 = sext i8 %6 to i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i8, i8* %1
%10 = load i32, i32* @stderr
%11 = call i32 @fputc(i8 signext %9, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"ch = %c\0A\00"
@stderr = global i32 0
@.str.2 = [6 x i8] c"pause\00"
define i32 @main01() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @fputc(i8 signext 97, i32 %1)
%3 = load i32, i32* @stdin
%4 = tail call signext i8 @fgetc(i32 %3)
%5 = sext i8 %4 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputc(i8 signext %4, i32 %7)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}