#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 */

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ rkillpid();
int /*<<< orphan*/ rs_warn(char *);
int sprintf(char *, char *, int);
int write(int, char *, int);
void createpid(int pid) {
  char spid[128];
  int fd, spidlen;
  rkillpid();
  if ((fd = open("/var/run/rtmpserver.pid", O_CREAT | O_RDWR,
                 S_IRUSR | S_IWUSR)) < 0) {
    rs_warn("open pidpath failed\n");
  }
  spidlen = sprintf(spid, "%d", pid);
  if (write(fd, spid, spidlen) != spidlen) {
    rs_warn("write pidpath failed\n");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<createpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <rkillpid@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
or     (%rax),%esi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    0x2e41(%rip),%rax
or     (%rax),%edx
lea    0xe60(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jge    11c0 <createpid+0x60>
lea    0xe5d(%rip),%rdi
call   1060 <rs_warn@plt>
lea    -0x90(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe5c(%rip),%rsi
call   1080 <sprintf@plt>
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x98(%rbp),%edx
call   1040 <write@plt>
cmp    -0x98(%rbp),%eax
je     120c <createpid+0xac>
lea    0xe29(%rip),%rdi
call   1060 <rs_warn@plt>
mov    -0x94(%rbp),%edi
call   1050 <close@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createpid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <rkillpid@plt>
mov    0x2e7a(%rip),%rax
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e38(%rip),%rax
mov    0x2e41(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe5e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b9 <createpid+0x59>
lea    0xe64(%rip),%rdi
call   1060 <rs_warn@plt>
lea    0xe6d(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14d,%edx
call   1080 <sprintf@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
je     11ec <createpid+0x8c>
lea    0xe49(%rip),%rdi
call   1060 <rs_warn@plt>
mov    %ebp,%edi
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"/var/run/rtmpserver.pid\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [21 x i8] c"open pidpath failed\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"write pidpath failed\0A\00"
define void @createpid(i32 %0) {
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (...) @rkillpid()
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_RDWR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
store i32 %13, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @rs_warn(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %2
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%23 = load i32, i32* %5
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
%25 = load i32, i32* %5
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 @rs_warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/run/rtmpserver.pid\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [21 x i8] c"open pidpath failed\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"write pidpath failed\0A\00"
define void @createpid(i32 %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @rkillpid()
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @rs_warn(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%17 = call i32 @write(i32 %11, i8* %3, i32 %16)
%18 = icmp eq i32 %17, %16
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @rs_warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = tail call i32 @close(i32 %11)
ret void
}