#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pr_stdio(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  printf("enter any character:");
  if (getchar() == EOF) {
    perror("getchar");
    return -1;
  }
  fputs("line from stderr.\n", stderr);
  pr_stdio("stdin", stdin);
  pr_stdio("stdout", stdout);
  pr_stdio("stderr", stderr);
  fp = fopen("stdio.c", "r");
  if (fp == NULL) {
    perror("fopen");
  }
  pr_stdio("fp", fp);
  fclose(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)
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <main+0x51>
lea    0xe65(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1267 <main+0xf7>
mov    0x2e08(%rip),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%rsi
lea    0xe48(%rip),%rdi
call   1070 <pr_stdio@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rsi
lea    0xe38(%rip),%rdi
call   1070 <pr_stdio@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rsi
lea    0xe29(%rip),%rdi
call   1070 <pr_stdio@plt>
lea    0xe24(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1247 <main+0xd7>
lea    0xe0a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1070 <pr_stdio@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
je     1225 <main+0xb5>
mov    0x2e35(%rip),%rbx
mov    (%rbx),%rcx
lea    0xe78(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%rsi
lea    0xe6b(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%rsi
lea    0xe5b(%rip),%rdi
call   1060 <pr_stdio@plt>
mov    (%rbx),%rsi
lea    0xe53(%rip),%rdi
call   1060 <pr_stdio@plt>
lea    0xe4e(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1238 <main+0xc8>
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
call   1060 <pr_stdio@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xde9(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
jmp    120a <main+0x9a>

LLVM IR (-O0):
@.str = [21 x i8] c"enter any character:\00"
@EOF = global i64 0
@.str.1 = [8 x i8] c"getchar\00"
@.str.2 = [19 x i8] c"line from stderr.\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"
@stdout = global i32* null
@.str.5 = [7 x i8] c"stderr\00"
@.str.6 = [8 x i8] c"stdio.c\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [6 x i8] c"fopen\00"
@.str.9 = [3 x i8] c"fp\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 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = call i64 (...) @getchar()
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %32
13: ; preds = %2
%14 = load i32*, i32** @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** @stdin
%17 = call i32 @pr_stdio(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** @stdout
%19 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** @stderr
%21 = call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %27
27: ; preds = %25, %13
%28 = load i32*, i32** %6
%29 = call i32 @pr_stdio(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %28)
%30 = load i32*, i32** %6
%31 = call i32 @fclose(i32* %30)
store i32 0, i32* %3
br label %32
32: ; preds = %27, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [21 x i8] c"enter any character:\00"
@EOF = global i64 0
@.str.1 = [8 x i8] c"getchar\00"
@.str.2 = [19 x i8] c"line from stderr.\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"
@stdout = global i32* null
@.str.5 = [7 x i8] c"stderr\00"
@.str.6 = [8 x i8] c"stdio.c\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [6 x i8] c"fopen\00"
@.str.9 = [3 x i8] c"fp\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 (...) @getchar()
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %25
9: ; preds = %2
%10 = load i32*, i32** @stderr
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 18, i64 1, i32* %10)
%12 = load i32*, i32** @stdin
%13 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %12)
%14 = load i32*, i32** @stdout
%15 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** @stderr
%17 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %16)
%18 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %22
22: ; preds = %20, %9
%23 = tail call i32 @pr_stdio(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %18)
%24 = tail call i32 @fclose(i32* %18)
br label %25
25: ; preds = %22, %7
%26 = phi i32 [ -1, %7 ], [ 0, %22 ]
ret i32 %26
}