#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*/ debugMsg(char *);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ writeFile(char *, char *);
int savePid(char *pid_name, int pid_int) {
  debugMsg("savePid() ...");
  if (pid_int == 0) {
    debugMsg("savePid() ... pid is 0 ...");
    pid_int = getpid();
  }
  debugMsg("savePid() ... pid is > 0 ...");
  char pid_char[512];
  char *pid_file;
  debugMsg("savePid() ... sprintf ...");
  sprintf(pid_char, "%d", pid_int);
  debugMsg("savePid() ... sel arg ...");
  if (strcmp(pid_name, (char *)"par") == 0) {
    pid_file = "/tmp/.pidlbr-dmn";
  } else if (strcmp(pid_name, (char *)"chi_1") == 0) {
    pid_file = "/tmp/.pidlbr-1";
  } else if (strcmp(pid_name, (char *)"chi_2") == 0) {
    pid_file = "/tmp/.pidlbr-2";
  } else {
    pid_file = "/tmp/.pidlbr-dmn";
  }
  debugMsg("savePid() ... ok ...");
  if (writeFile(pid_file, pid_char) == 0) {
    return 0;
  } else {
    return pid_int;
  }
}


x86 assembly (clang, -O0):
<savePid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <debugMsg@plt>
cmpl   $0x0,-0x14(%rbp)
jne    118e <savePid+0x3e>
lea    0xe8f(%rip),%rdi
call   1040 <debugMsg@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
lea    0xe94(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xea5(%rip),%rdi
call   1040 <debugMsg@plt>
lea    -0x220(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xea9(%rip),%rsi
call   1070 <sprintf@plt>
lea    0xea0(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f5 <savePid+0xa5>
lea    0xe98(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    1267 <savePid+0x117>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1222 <savePid+0xd2>
lea    0xe82(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    1262 <savePid+0x112>
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    124f <savePid+0xff>
lea    0xe6a(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    125d <savePid+0x10d>
lea    0xe2b(%rip),%rax
mov    %rax,-0x228(%rbp)
jmp    1262 <savePid+0x112>
jmp    1267 <savePid+0x117>
lea    0xe4e(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x228(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1060 <writeFile@plt>
cmp    $0x0,%rax
jne    129c <savePid+0x14c>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <savePid+0x152>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<savePid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe99(%rip),%rdi
call   1040 <debugMsg@plt>
test   %ebp,%ebp
jne    1185 <savePid+0x35>
lea    0xe97(%rip),%rdi
call   1040 <debugMsg@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
lea    0xe9d(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xeae(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xebc(%rip),%rsi
mov    %rsp,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
lea    0xeae(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xebc(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1208 <savePid+0xb8>
lea    0xebd(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1211 <savePid+0xc1>
lea    0xebe(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xeb2(%rip),%rax
lea    0xe7f(%rip),%rbx
cmove  %rax,%rbx
jmp    1218 <savePid+0xc8>
lea    0xe72(%rip),%rbx
jmp    1218 <savePid+0xc8>
lea    0xe80(%rip),%rbx
lea    0xe9d(%rip),%rdi
call   1040 <debugMsg@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <writeFile@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %ecx,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"savePid() ...\00"
@.str.1 = [27 x i8] c"savePid() ... pid is 0 ...\00"
@.str.2 = [29 x i8] c"savePid() ... pid is > 0 ...\00"
@.str.3 = [26 x i8] c"savePid() ... sprintf ...\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [26 x i8] c"savePid() ... sel arg ...\00"
@.str.6 = [4 x i8] c"par\00"
@.str.7 = [17 x i8] c"/tmp/.pidlbr-dmn\00"
@.str.8 = [6 x i8] c"chi_1\00"
@.str.9 = [15 x i8] c"/tmp/.pidlbr-1\00"
@.str.10 = [6 x i8] c"chi_2\00"
@.str.11 = [15 x i8] c"/tmp/.pidlbr-2\00"
@.str.12 = [21 x i8] c"savePid() ... ok ...\00"
define i32 @savePid(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 @debugMsg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (...) @getpid()
store i32 %13, i32* %5
br label %14
14: ; preds = %11, %2
%15 = call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %5
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %14
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %38
25: ; preds = %14
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8** %7
br label %37
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8** %7
br label %36
35: ; preds = %30
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %36
36: ; preds = %35, %34
br label %37
37: ; preds = %36, %29
br label %38
38: ; preds = %37, %24
%39 = call i32 @debugMsg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%40 = load i8*, i8** %7
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%42 = call i64 @writeFile(i8* %40, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 0, i32* %3
br label %47
45: ; preds = %38
%46 = load i32, i32* %5
store i32 %46, i32* %3
br label %47
47: ; preds = %45, %44
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [14 x i8] c"savePid() ...\00"
@.str.1 = [27 x i8] c"savePid() ... pid is 0 ...\00"
@.str.2 = [29 x i8] c"savePid() ... pid is > 0 ...\00"
@.str.3 = [26 x i8] c"savePid() ... sprintf ...\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [26 x i8] c"savePid() ... sel arg ...\00"
@.str.6 = [4 x i8] c"par\00"
@.str.7 = [17 x i8] c"/tmp/.pidlbr-dmn\00"
@.str.8 = [6 x i8] c"chi_1\00"
@.str.9 = [15 x i8] c"/tmp/.pidlbr-1\00"
@.str.10 = [6 x i8] c"chi_2\00"
@.str.11 = [15 x i8] c"/tmp/.pidlbr-2\00"
@.str.12 = [21 x i8] c"savePid() ... ok ...\00"
define i32 @savePid(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = tail call i32 @debugMsg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @debugMsg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @getpid()
br label %9
9: ; preds = %6, %2
%10 = phi i32 [ %8, %6 ], [ %1, %2 ]
%11 = tail call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%13 = tail call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%15 = tail call i32 @debugMsg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %9
%19 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0)
br label %25
25: ; preds = %21, %18, %9
%26 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), %9 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), %18 ], [ %24, %21 ]
%27 = tail call i32 @debugMsg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%28 = call i64 @writeFile(i8* %26, i8* %12)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i32 0, i32 %10
ret i32 %30
}