#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ getc(int /*<<< orphan*/ *);
scalar_t__ getchar();
int /*<<< orphan*/ pr_stdio(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(void) {
  FILE *fp = 0;
  fputs("enter any character\n", stdout);
  if (getchar() == EOF)
    err_sys("getchar error");
  fputs("one line to standard error\n", stderr);
  pr_stdio("stdin", stdin);
  pr_stdio("stdout", stdout);
  pr_stdio("stderr", stderr);
  if ((fp = fopen("/etc/motd", "r")) == NULL)
    err_sys("fopen error");
  if (getc(fp) == EOF)
    err_sys("getc error");
  pr_stdio("/etc/motd", fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rsi
lea    0xe78(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
jne    11b0 <main+0x50>
lea    0xe6a(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rsi
lea    0xe68(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%rsi
lea    0xe58(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%rsi
lea    0xe49(%rip),%rdi
call   1060 <pr_stdio@plt>
lea    0xe44(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1235 <main+0xd5>
lea    0xe2d(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%rax
jne    125a <main+0xfa>
lea    0xe14(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x10(%rbp),%rsi
lea    0xdee(%rip),%rdi
call   1060 <pr_stdio@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e5c(%rip),%r15
mov    (%r15),%rcx
lea    0xe8a(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e4d(%rip),%r14
cmp    (%r14),%rax
jne    11a4 <main+0x44>
lea    0xe76(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x2e25(%rip),%rbx
mov    (%rbx),%rcx
lea    0xe6e(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rsi
lea    0xe6a(%rip),%rdi
call   1050 <pr_stdio@plt>
mov    (%r15),%rsi
lea    0xe61(%rip),%rdi
call   1050 <pr_stdio@plt>
mov    (%rbx),%rsi
lea    0xe59(%rip),%rdi
call   1050 <pr_stdio@plt>
lea    0xe54(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    121f <main+0xbf>
lea    0xe43(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r14),%rax
jne    1238 <main+0xd8>
lea    0xe36(%rip),%rdi
call   1030 <err_sys@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
call   1050 <pr_stdio@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"enter any character\0A\00"
@stdout = global i32* null
@EOF = global i64 0
@.str.1 = [14 x i8] c"getchar error\00"
@.str.2 = [28 x i8] c"one line to standard error\0A\00"
@stderr = global i32* null
@.str.3 = [6 x i8] c"stdin\00"
@stdin = global i32* null
@.str.4 = [7 x i8] c"stdout\00"
@.str.5 = [7 x i8] c"stderr\00"
@.str.6 = [10 x i8] c"/etc/motd\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [12 x i8] c"fopen error\00"
@.str.9 = [11 x i8] c"getc error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
%3 = load i32*, i32** @stdout
%4 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = call i64 (...) @getchar()
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32*, i32** @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** @stdin
%14 = call i32 @pr_stdio(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** @stdout
%16 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** @stderr
%18 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %17)
%19 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %19, i32** %2
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
%24 = load i32*, i32** %2
%25 = call i64 @getc(i32* %24)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = load i32*, i32** %2
%32 = call i32 @pr_stdio(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"enter any character\0A\00"
@stdout = global i32* null
@EOF = global i64 0
@.str.1 = [14 x i8] c"getchar error\00"
@.str.2 = [28 x i8] c"one line to standard error\0A\00"
@stderr = global i32* null
@.str.3 = [6 x i8] c"stdin\00"
@stdin = global i32* null
@.str.4 = [7 x i8] c"stdout\00"
@.str.5 = [7 x i8] c"stderr\00"
@.str.6 = [10 x i8] c"/etc/motd\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [12 x i8] c"fopen error\00"
@.str.9 = [11 x i8] c"getc error\00"
define i32 @main() {
%1 = load i32*, i32** @stdout
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 20, i64 1, i32* %1)
%3 = tail call i64 (...) @getchar()
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32*, i32** @stderr
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %9)
%11 = load i32*, i32** @stdin
%12 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** @stdout
%14 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** @stderr
%16 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %15)
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %8
%20 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %21
21: ; preds = %19, %8
%22 = tail call i64 @getc(i32* %17)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32* %17)
ret i32 0
}