#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 */
int EOF;
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int getchar();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ *tmpfile();
FILE *O(char *u) {
  int i;
  FILE *Q;
  if (!(Q = fopen(u, "r")) && !strcmp("-", u)) {
    if ((Q = tmpfile())) {
      while ((i = getchar()) != EOF)
        fputc(i, Q);
      rewind(Q);
    }
  }
  if (!Q)
    err(2, "%s", u);
  return Q;
}


x86 assembly (clang, -O0):
<O>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1205 <O+0x95>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1205 <O+0x95>
mov    $0x0,%al
call   1050 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1200 <O+0x90>
jmp    11cd <O+0x5d>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%eax
je     11f7 <O+0x87>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <fputc@plt>
jmp    11cd <O+0x5d>
mov    -0x18(%rbp),%rdi
call   1030 <rewind@plt>
jmp    1205 <O+0x95>
cmpq   $0x0,-0x18(%rbp)
jne    1225 <O+0xb5>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xde4(%rip),%rsi
call   1080 <err@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<O>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11fe <O+0x8e>
lea    0xe70(%rip),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b6 <O+0x46>
lea    0xe5f(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
call   1080 <err@plt>
xor    %ebx,%ebx
jmp    11fe <O+0x8e>
xor    %eax,%eax
call   1050 <tmpfile@plt>
test   %rax,%rax
je     119e <O+0x2e>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e15(%rip),%r14
cmp    (%r14),%eax
je     11f6 <O+0x86>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r14),%eax
jne    11e0 <O+0x70>
mov    %rbx,%rdi
call   1030 <rewind@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"-\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define i32* @O(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %28, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %8
%13 = call i32* (...) @tmpfile()
store i32* %13, i32** %4
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %27
15: ; preds = %12
br label %16
16: ; preds = %20, %15
%17 = call i32 (...) @getchar()
store i32 %17, i32* %3
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32*, i32** %4
%23 = call i32 @fputc(i32 %21, i32* %22)
br label %16
24: ; preds = %16
%25 = load i32*, i32** %4
%26 = call i32 @rewind(i32* %25)
br label %27
27: ; preds = %24, %12
br label %28
28: ; preds = %27, %8, %1
%29 = load i32*, i32** %4
%30 = icmp ne i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i8*, i8** %2
%33 = call i32 @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %28
%35 = load i32*, i32** %4
ret i32* %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"-\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define i32* @O(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = tail call i32* (...) @tmpfile()
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = tail call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %10, %14
%15 = phi i32 [ %17, %14 ], [ %11, %10 ]
%16 = tail call i32 @fputc(i32 %15, i32* %8)
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %10
%21 = tail call i32 @rewind(i32* %8)
br label %24
22: ; preds = %7, %4
%23 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %20, %1, %22
%25 = phi i32* [ null, %22 ], [ %8, %20 ], [ %2, %1 ]
ret i32* %25
}