#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*/ asprintf(char **, char *, char const *, char const *);
scalar_t__ strcmp(char const *, char *);
char *set_pidfile(const char *root, const char *cmd) {
  char *path = NULL;
  if (!root || !cmd)
    goto out;
  if (strcmp(root, "/") == 0)
    root = "";
  asprintf(&path, "%s/var/run/%s.pid", root, cmd);
out:
  return path;
}


x86 assembly (clang, -O0):
<set_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114e <set_pidfile+0x2e>
cmpq   $0x0,-0x10(%rbp)
jne    1153 <set_pidfile+0x33>
jmp    1190 <set_pidfile+0x70>
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1178 <set_pidfile+0x58>
lea    0xe8d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1040 <asprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pidfile>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
xor    %eax,%eax
test   %rdi,%rdi
je     116e <set_pidfile+0x4e>
mov    %rsi,%r14
test   %rsi,%rsi
je     116e <set_pidfile+0x4e>
mov    %rdi,%rbx
lea    0xebb(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
lea    0xead(%rip),%rdx
cmovne %rbx,%rdx
lea    0xea3(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rcx
call   1040 <asprintf@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [18 x i8] c"%s/var/run/%s.pid\00"
define i8* @set_pidfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8, %2
br label %21
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %17
17: ; preds = %16, %12
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %19)
br label %21
21: ; preds = %17, %11
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [18 x i8] c"%s/var/run/%s.pid\00"
define i8* @set_pidfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
%12 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %1)
%13 = load i8*, i8** %3
br label %14
14: ; preds = %2, %8
%15 = phi i8* [ null, %2 ], [ %13, %8 ]
ret i8* %15
}