#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*/ sprintf(char *, char *, int);
void pid_write(int port, int pid) {
  char path[256];
  FILE *out = NULL;
  sprintf(path, "/tmp/krakws_%d.pid", port);
  if ((out = fopen(path, "w"))) {
    fprintf(out, "%d", pid);
    fclose(out);
  }
}


x86 assembly (clang, -O0):
<pid_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe93(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     11b8 <pid_write+0x78>
mov    -0x118(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pid_write>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebp
mov    %edi,%edx
lea    0xeac(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <pid_write+0x58>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/krakws_%d.pid\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @pid_write(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%10 = tail call i32 @fclose(i32* %6)
br label %11
11: ; preds = %8, %2
ret void
}