#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 /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ pidfile_create(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pidfile_destroy(char *);
int pidfile_getpgid(char *);
int pidfile_getpid(char *);
int pidfile_getsid(char *);
int /*<<< orphan*/ pidfile_kill(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ usleep(int);
void test_pidfile(void) {
  pidfile_create("testpidfile.pid", getpid());
  usleep(1000);
  printf("pid: %d\n", pidfile_getpid("testpidfile.pid"));
  usleep(1000);
  pidfile_kill("testpidfile.pid", SIGHUP);
  usleep(1000);
  printf("sid: %d\n", pidfile_getsid("testpidfile.pid"));
  usleep(1000);
  printf("gid: %d\n", pidfile_getpgid("testpidfile.pid"));
  usleep(1000);
  pidfile_destroy("testpidfile.pid");
}


x86 assembly (clang, -O0):
<test_pidfile>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xe5c(%rip),%rdi
call   1080 <pidfile_create@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
lea    0xe46(%rip),%rdi
call   10a0 <pidfile_getpid@plt>
mov    %eax,%esi
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1070 <pidfile_kill@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
lea    0xe03(%rip),%rdi
call   1030 <pidfile_getsid@plt>
mov    %eax,%esi
lea    0xe0e(%rip),%rdi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
lea    0xddf(%rip),%rdi
call   1040 <pidfile_getpgid@plt>
mov    %eax,%esi
lea    0xdf3(%rip),%rdi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
lea    0xdbb(%rip),%rdi
call   1090 <pidfile_destroy@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pidfile>:
push   %rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe61(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <pidfile_create@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    %rbx,%rdi
call   10a0 <pidfile_getpid@plt>
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <pidfile_kill@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    %rbx,%rdi
call   1030 <pidfile_getsid@plt>
lea    0xe1c(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    %rbx,%rdi
call   1040 <pidfile_getpgid@plt>
lea    0xe05(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0x3e8,%edi
call   10b0 <usleep@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1090 <pidfile_destroy@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"testpidfile.pid\00"
@.str.1 = [9 x i8] c"pid: %d\0A\00"
@SIGHUP = global i32 0
@.str.2 = [9 x i8] c"sid: %d\0A\00"
@.str.3 = [9 x i8] c"gid: %d\0A\00"
define void @test_pidfile() {
%1 = call i32 (...) @getpid()
%2 = call i32 @pidfile_create(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = call i32 @usleep(i32 1000)
%4 = call i32 @pidfile_getpid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = call i32 @usleep(i32 1000)
%7 = load i32, i32* @SIGHUP
%8 = call i32 @pidfile_kill(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @usleep(i32 1000)
%10 = call i32 @pidfile_getsid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 @usleep(i32 1000)
%13 = call i32 @pidfile_getpgid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 @usleep(i32 1000)
%16 = call i32 @pidfile_destroy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"testpidfile.pid\00"
@.str.1 = [9 x i8] c"pid: %d\0A\00"
@SIGHUP = global i32 0
@.str.2 = [9 x i8] c"sid: %d\0A\00"
@.str.3 = [9 x i8] c"gid: %d\0A\00"
define void @test_pidfile() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 @pidfile_create(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @usleep(i32 1000)
%4 = tail call i32 @pidfile_getpid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @usleep(i32 1000)
%7 = load i32, i32* @SIGHUP
%8 = tail call i32 @pidfile_kill(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @usleep(i32 1000)
%10 = tail call i32 @pidfile_getsid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @usleep(i32 1000)
%13 = tail call i32 @pidfile_getpgid(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 @usleep(i32 1000)
%16 = tail call i32 @pidfile_destroy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret void
}