#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 */
scalar_t__ AMCAppAlreadyRunning(char *, char *, int *);
int /*<<< orphan*/ AMCAppDaemonize(int /*<<< orphan*/);
int /*<<< orphan*/ AMCPrintf(char *, ...);
int /*<<< orphan*/ sleep(int);
int trueMain(int argc, char *argv[]) {
  int pid = -1;
  AMCAppDaemonize(0);
  if (AMCAppAlreadyRunning("/var/tmp/tmp/tmp", "tmp.pid", &pid)) {
    AMCPrintf("Pid %d already running", pid);
    return -1;
  } else {
    AMCPrintf("Got pid: %d", pid);
  }
  while (1) {
    AMCPrintf("Sleep...");
    sleep(1);
  }
ENDS:
  return 0;
}


x86 assembly (clang, -O0):
<trueMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
xor    %edi,%edi
call   1050 <AMCAppDaemonize@plt>
lea    0xe9c(%rip),%rdi
lea    0xea6(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <AMCAppAlreadyRunning@plt>
cmp    $0x0,%rax
je     119b <trueMain+0x5b>
mov    -0x14(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <AMCPrintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <trueMain+0x8e>
mov    -0x14(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <AMCPrintf@plt>
jmp    11b1 <trueMain+0x71>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <AMCPrintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11b1 <trueMain+0x71>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trueMain>:
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
xor    %edi,%edi
call   1050 <AMCAppDaemonize@plt>
lea    0xea5(%rip),%rdi
lea    0xeaf(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1030 <AMCAppAlreadyRunning@plt>
mov    0xc(%rsp),%esi
test   %rax,%rax
je     118e <trueMain+0x4e>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <AMCPrintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <AMCPrintf@plt>
lea    0xe99(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <AMCPrintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11b0 <trueMain+0x70>

LLVM IR (-O0):
@.str = [17 x i8] c"/var/tmp/tmp/tmp\00"
@.str.1 = [8 x i8] c"tmp.pid\00"
@.str.2 = [23 x i8] c"Pid %d already running\00"
@.str.3 = [12 x i8] c"Got pid: %d\00"
@.str.4 = [9 x i8] c"Sleep...\00"
define i32 @trueMain(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%7 = call i32 @AMCAppDaemonize(i32 0)
%8 = call i64 @AMCAppAlreadyRunning(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %11)
store i32 -1, i32* %3
br label %21
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13
br label %17
17: ; preds = %16, %17
%18 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @sleep(i32 1)
br label %17
20: ; No predecessors!
store i32 0, i32* %3
br label %21
21: ; preds = %20, %10
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [17 x i8] c"/var/tmp/tmp/tmp\00"
@.str.1 = [8 x i8] c"tmp.pid\00"
@.str.2 = [23 x i8] c"Pid %d already running\00"
@.str.3 = [12 x i8] c"Got pid: %d\00"
@.str.4 = [9 x i8] c"Sleep...\00"
define i32 @trueMain(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%5 = tail call i32 @AMCAppDaemonize(i32 0)
%6 = call i64 @AMCAppAlreadyRunning(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = icmp eq i64 %6, 0
%8 = load i32, i32* %3
br i1 %7, label %11, label %9
9: ; preds = %2
%10 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %8)
ret i32 -1
11: ; preds = %2
%12 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %8)
br label %13
13: ; preds = %13, %11
%14 = call i32 (i8*, ...) @AMCPrintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @sleep(i32 1)
br label %13
}