#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stderr;
FILE *Sfopen(char *filename) {
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Error :");
    fprintf(stderr, filename);
    fprintf(stderr, " is not exist!\n");
    FILE *fp_error;
    fp_error = fopen("Error.txt", "w");
    fprintf(fp_error, "Error :");
    fprintf(fp_error, filename);
    fprintf(fp_error, " is not exist!\n");
    fclose(fp_error);
    exit(1);
  }
  return fp;
}


x86 assembly (clang, -O0):
<Sfopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1201 <Sfopen+0xc1>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rdi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%rdi
lea    0xe65(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe69(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sfopen>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1178 <Sfopen+0x28>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e61(%rip),%r15
mov    (%r15),%rcx
lea    0xe79(%rip),%r14
mov    $0x7,%esi
mov    $0x1,%edx
mov    %r14,%rdi
call   1070 <fwrite@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
call   1040 <fprintf@plt>
mov    (%r15),%rcx
lea    0xe5a(%rip),%r15
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r15,%rdi
call   1070 <fwrite@plt>
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
mov    $0x7,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <fprintf@plt>
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [8 x i8] c"Error :\00"
@.str.2 = [16 x i8] c" is not exist!\0A\00"
@.str.3 = [10 x i8] c"Error.txt\00"
@.str.4 = [2 x i8] c"w\00"
define i32* @Sfopen(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** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i32*, i32** @stderr
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32*, i32** @stderr
%13 = load i8*, i8** %2
%14 = call i32 @fprintf(i32* %12, i8* %13)
%15 = load i32*, i32** @stderr
%16 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %4
%18 = load i32*, i32** %4
%19 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32*, i32** %4
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32* %20, i8* %21)
%23 = load i32*, i32** %4
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %1
%29 = load i32*, i32** %3
ret i32* %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32* null
@.str.1 = [8 x i8] c"Error :\00"
@.str.2 = [16 x i8] c" is not exist!\0A\00"
@.str.3 = [10 x i8] c"Error.txt\00"
@.str.4 = [2 x i8] c"w\00"
define noalias i32* @Sfopen(i8* nocapture %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 %17
4: ; preds = %1
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 7, i64 1, i32* %5)
%7 = load i32*, i32** @stderr
%8 = tail call i32 @fprintf(i32* %7, i8* %0)
%9 = load i32*, i32** @stderr
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 15, i64 1, i32* %9)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 7, i64 1, i32* %11)
%13 = tail call i32 @fprintf(i32* %11, i8* %0)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 15, i64 1, i32* %11)
%15 = tail call i32 @fclose(i32* %11)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %1
ret i32* %2
}