#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ warnx(char *, char *);
int irm_create_file(char *log_path) {
  int ret = 0;
  FILE *fd;
  char *s = malloc(256);
  fd = fopen("./irm_log002.txt", "ab");
  if (fd == NULL) {
    warnx("Could not open data debug file %s", log_path);
    ret = -1;
  }
  fclose(fd);
  free(s);
  return ret;
}


x86 assembly (clang, -O0):
<irm_create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe88(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <irm_create_file+0x5a>
mov    -0x8(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <warnx@plt>
movl   $0xffffffff,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irm_create_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe92(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
test   %rax,%rax
jne    1198 <irm_create_file+0x48>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1050 <warnx@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"./irm_log002.txt\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [34 x i8] c"Could not open data debug file %s\00"
define i32 @irm_create_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %11)
store i32 -1, i32* %3
br label %13
13: ; preds = %10, %1
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = load i8*, i8** %5
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [17 x i8] c"./irm_log002.txt\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [34 x i8] c"Could not open data debug file %s\00"
define i32 @irm_create_file(i8* %0) {
%2 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %1
%8 = phi i32 [ -1, %5 ], [ 0, %1 ]
%9 = tail call i32 @fclose(i32* %3)
%10 = tail call i32 @free(i8* %2)
ret i32 %8
}