#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 /*<<< orphan*/ free(char *);
char *getenv(char *);
int getpid();
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
void create_pid_file(void) {
  char *home;
  char *pid;
  FILE *fp;
  home = getenv("HOME");
  if (home == NULL)
    return;
  pid = malloc(strlen(home) + 11);
  sprintf(pid, "%s/.wmix.pid", home);
  fp = fopen(pid, "w");
  if (fp) {
    fprintf(fp, "%d\n", getpid());
    fclose(fp);
  }
  free(pid);
}


x86 assembly (clang, -O0):
<create_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b8 <create_pid_file+0x28>
jmp    1237 <create_pid_file+0xa7>
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0xb,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe25(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     122e <create_pid_file+0x9e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xdf4(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_pid_file>:
push   %r14
push   %rbx
push   %rax
lea    0xe65(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1214 <create_pid_file+0x84>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <strlen@plt>
lea    0xb(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe42(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1205 <create_pid_file+0x75>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [13 x i8] c"%s/.wmix.pid\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define void @create_pid_file() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32*
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
br label %29
8: ; preds = %0
%9 = load i8*, i8** %1
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 11
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = load i8*, i8** %1
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %3
%18 = load i32*, i32** %3
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %8
%21 = load i32*, i32** %3
%22 = call i32 (...) @getpid()
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %20, %8
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %26, %7
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [13 x i8] c"%s/.wmix.pid\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define void @create_pid_file() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 11
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%8 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = tail call i32 @fclose(i32* %8)
br label %14
14: ; preds = %10, %3
%15 = tail call i32 @free(i8* %6)
br label %16
16: ; preds = %0, %14
ret void
}