#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
FILE *my_fopen(const char *filename, const char *mode, char *file, int line) {
  FILE *openfile = NULL;
  openfile = fopen(filename, mode);
  if (!openfile) {
    fprintf(stderr, "Erreur lors d'un fopen de '%s' en mode '%s' ", filename,
            mode);
    perror("");
    fprintf(stderr, "Ligne %d du fichier %s.\n", line, file);
    exit(EXIT_FAILURE);
  }
  return (openfile);
}


x86 assembly (clang, -O0):
<my_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d2 <my_fopen+0x92>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    0xea4(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fopen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <fopen@plt>
test   %rax,%rax
je     1167 <my_fopen+0x27>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e72(%rip),%r12
mov    (%r12),%edi
lea    0xe87(%rip),%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xeb8(%rip),%rdi
call   1050 <perror@plt>
mov    (%r12),%edi
lea    0xe90(%rip),%rsi
mov    %r15d,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Erreur lors d'un fopen de '%s' en mode '%s' \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [25 x i8] c"Ligne %d du fichier %s.\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @my_fopen(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32* null, i32** %9
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i32* @fopen(i8* %10, i8* %11)
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp ne i32* %13, null
br i1 %14, label %27, label %15
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
%20 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = load i32, i32* %8
%23 = load i8*, i8** %7
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %4
%28 = load i32*, i32** %9
ret i32* %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Erreur lors d'un fopen de '%s' en mode '%s' \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [25 x i8] c"Ligne %d du fichier %s.\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i32* @my_fopen(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* %1)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %3, i8* %2)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
ret i32* %5
}