#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 /*<<< orphan*/ free(char *);
char *get_lockfile_path();
int /*<<< orphan*/ stderr;
void create_lockfile(const char *content) {
  FILE *fp = NULL;
  char *path = NULL;
  path = get_lockfile_path();
  if (path == NULL)
    return;
  fp = fopen(path, "w");
  if (fp == NULL) {
    free(path);
    fprintf(stderr, "Failed to create lock file\n");
    return;
  }
  fprintf(fp, "%s", content);
  fclose(fp);
  free(path);
}


x86 assembly (clang, -O0):
<create_lockfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <get_lockfile_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <create_lockfile+0x37>
jmp    11f4 <create_lockfile+0xa4>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cc <create_lockfile+0x7c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e2a(%rip),%rax
movslq (%rax),%rdi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11f4 <create_lockfile+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_lockfile>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <get_lockfile_path@plt>
test   %rax,%rax
je     11ae <create_lockfile+0x4e>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b4 <create_lockfile+0x54>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2e1d(%rip),%rax
movslq (%rax),%rcx
lea    0xe35(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <fwrite@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Failed to create lock file\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @create_lockfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
store i8* null, i8** %4
%5 = call i8* (...) @get_lockfile_path()
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
br label %29
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = call i32 @free(i8* %15)
%17 = load i32, i32* @stderr
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %29
21: ; preds = %9
%22 = load i32*, i32** %3
%23 = load i8*, i8** %2
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %21, %14, %8
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Failed to create lock file\0A\00"
define void @create_lockfile(i8* nocapture %0) {
%2 = tail call i8* (...) @get_lockfile_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i32 @free(i8* %2)
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 27, i64 1, i32* %11)
br label %17
13: ; preds = %4
%14 = tail call i32 @fputs(i8* %0, i32* %5)
%15 = tail call i32 @fclose(i32* %5)
%16 = tail call i32 @free(i8* %2)
br label %17
17: ; preds = %1, %13, %7
ret void
}