#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
scalar_t__ system(char *);
void cleanup_pidfile() {
  char username[1024];
  char dirname[1024];
  char syscmdbuff[1024];
  sprintf(username, getenv("USER"));
  if (strlen(username) == 0) {
    fprintf(stderr, "Couldn't get users name (getenv)\n");
    exit(1);
  }
  sprintf(dirname, "/tmp/%s/%d", username, getpid());
  sprintf(syscmdbuff, "rm -rf %s", dirname);
  system(syscmdbuff);
  if (0 != system(syscmdbuff)) {
    fprintf(stderr, "Command: ``%s`` failed\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<cleanup_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
lea    -0x400(%rbp),%rax
mov    %rax,-0xc08(%rbp)
lea    0xe70(%rip),%rdi
call   1030 <getenv@plt>
mov    -0xc08(%rbp),%rdi
mov    %rax,%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x400(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    11db <cleanup_pidfile+0x6b>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x800(%rbp),%rax
mov    %rax,-0xc18(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0xc10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xc18(%rbp),%rdi
mov    -0xc10(%rbp),%rdx
mov    %eax,%ecx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0xc00(%rbp),%rdi
lea    -0x800(%rbp),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0xc00(%rbp),%rdi
call   1060 <system@plt>
lea    -0xc00(%rbp),%rdi
call   1060 <system@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     127d <cleanup_pidfile+0x10d>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanup_pidfile>:
push   %r14
push   %rbx
sub    $0xc08,%rsp
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
cmpb   $0x0,(%rsp)
je     11ea <cleanup_pidfile+0x8a>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe90(%rip),%rsi
lea    0x800(%rsp),%r14
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe7d(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
test   %rax,%rax
jne    11fc <cleanup_pidfile+0x9c>
add    $0xc08,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2def(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
jmp    120c <cleanup_pidfile+0xac>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Couldn't get users name (getenv)\0A\00"
@.str.2 = [11 x i8] c"/tmp/%s/%d\00"
@.str.3 = [10 x i8] c"rm -rf %s\00"
@.str.4 = [24 x i8] c"Command: ``%s`` failed\0A\00"
define void @cleanup_pidfile() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* %5)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i64 @system(i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = call i64 @system(i8* %24)
%26 = icmp ne i64 0, %25
br i1 %26, label %27, label %31
27: ; preds = %14
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Couldn't get users name (getenv)\0A\00"
@.str.2 = [11 x i8] c"/tmp/%s/%d\00"
@.str.3 = [10 x i8] c"rm -rf %s\00"
@.str.4 = [24 x i8] c"Command: ``%s`` failed\0A\00"
define void @cleanup_pidfile() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) %7)
%9 = load i8, i8* %4
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = tail call i32 (...) @getpid()
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %16)
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%19 = call i64 @system(i8* %6)
%20 = call i64 @system(i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %15
ret void
}