#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(int argc, char **argv) {
  FILE *fp;
  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 on /etc/motd");
  }
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <main+0x4f>
lea    0xe6b(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rsi
lea    0xe63(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%rsi
lea    0xe59(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rsi
lea    0xe4a(%rip),%rdi
call   1060 <pr_stdio@plt>
lea    0xe54(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1234 <main+0xd4>
lea    0xe24(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%rax
jne    1259 <main+0xf9>
lea    0xe18(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%rsi
lea    0xdfe(%rip),%rdi
call   1060 <pr_stdio@plt>
xor    %eax,%eax
add    $0x20,%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    0xe63(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    121f <main+0xbf>
lea    0xe39(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r14),%rax
jne    1238 <main+0xd8>
lea    0xe39(%rip),%rdi
call   1030 <err_sys@plt>
lea    0xe23(%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 = [25 x i8] c"fopen error on /etc/motd\00"
@.str.9 = [11 x i8] c"getc error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32*, i32** @stdout
%8 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = call i64 (...) @getchar()
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32*, i32** @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** @stdin
%18 = call i32 @pr_stdio(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %17)
%19 = load i32*, i32** @stdout
%20 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %19)
%21 = load i32*, i32** @stderr
%22 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %21)
%23 = 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* %23, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load i32*, i32** %6
%29 = call i64 @getc(i32* %28)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32*, i32** %6
%36 = call i32 @pr_stdio(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32* %35)
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 = [25 x i8] c"fopen error on /etc/motd\00"
@.str.9 = [11 x i8] c"getc error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32*, i32** @stdout
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 20, i64 1, i32* %3)
%5 = tail call i64 (...) @getchar()
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail 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, %2
%11 = load i32*, i32** @stderr
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %11)
%13 = load i32*, i32** @stdin
%14 = tail 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 = tail 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 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %17)
%19 = 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))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = tail call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
%24 = tail call i64 @getc(i32* %19)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32* %19)
ret i32 0
}