#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 */
struct stream {
  int dummy;
};

/* Variables and functions */
struct stream *cpp_stream(struct stream *);
int /*<<< orphan*/ exit(int);
struct stream *file_stream(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  struct stream *stdin_stream = file_stream("<stdin>", stdin);
  struct stream *cpp;
  if (!stdin_stream) {
    fprintf(stderr, "couldn't allocate stdin stream\n");
    exit(1);
  }
  cpp = cpp_stream(stdin_stream);
  if (!cpp) {
    fprintf(stderr, "couldn't allocate cpp stream\n");
    exit(1);
  }
  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    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <file_stream@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1199 <main+0x59>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <cpp_stream@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <main+0x90>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <file_stream@plt>
test   %rax,%rax
je     116c <main+0x2c>
mov    %rax,%rdi
call   1030 <cpp_stream@plt>
test   %rax,%rax
je     117e <main+0x3e>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
jmp    118e <main+0x4e>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stream = type { i32 }
@.str = [8 x i8] c"<stdin>\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"couldn't allocate stdin stream\0A\00"
@.str.2 = [30 x i8] c"couldn't allocate cpp stream\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stream*
%7 = alloca %struct.stream*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdin
%9 = call %struct.stream* @file_stream(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
store %struct.stream* %9, %struct.stream** %6
%10 = load %struct.stream*, %struct.stream** %6
%11 = icmp ne %struct.stream* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load %struct.stream*, %struct.stream** %6
%18 = call %struct.stream* @cpp_stream(%struct.stream* %17)
store %struct.stream* %18, %struct.stream** %7
%19 = load %struct.stream*, %struct.stream** %7
%20 = icmp ne %struct.stream* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
%struct.stream = type { i32 }
@.str = [8 x i8] c"<stdin>\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"couldn't allocate stdin stream\0A\00"
@.str.2 = [30 x i8] c"couldn't allocate cpp stream\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdin
%4 = tail call %struct.stream* @file_stream(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq %struct.stream* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call %struct.stream* @cpp_stream(%struct.stream* %4)
%12 = icmp eq %struct.stream* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
ret i32 0
}