#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ perror(char *);
void my_fprintf(char *path) {
  FILE *fp = NULL;
  fp = fopen(path, "w+");
  if (fp == NULL) {
    perror("my_fprintf fopen");
    return;
  }
  fprintf(fp, "%d %d %d\n", 1, 2, 3);
  if (fp != NULL) {
    fclose(fp);
    fp = NULL;
  }
}


x86 assembly (clang, -O0):
<my_fprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <my_fprintf+0x44>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
jmp    11c0 <my_fprintf+0x80>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
call   1040 <fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c0 <my_fprintf+0x80>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x10(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fprintf>:
push   %rbx
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117d <my_fprintf+0x3d>
mov    %rax,%rbx
lea    0xeb8(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
call   1040 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <fclose@plt>
lea    0xe7f(%rip),%rdi
pop    %rbx
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [17 x i8] c"my_fprintf fopen\00"
@.str.2 = [10 x i8] c"%d %d %d\0A\00"
define void @my_fprintf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
store i32* null, i32** %3
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %18
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 2, i32 3)
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
store i32* null, i32** %3
br label %18
18: ; preds = %8, %15, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [17 x i8] c"my_fprintf fopen\00"
@.str.2 = [10 x i8] c"%d %d %d\0A\00"
define void @my_fprintf(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %9
6: ; preds = %1
%7 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 2, i32 3)
%8 = tail call i32 @fclose(i32* %2)
br label %9
9: ; preds = %6, %4
ret void
}