#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
int /*<<< orphan*/ execl(char *, char *, char const *, char const *,
                         int /*<<< orphan*/ *);
scalar_t__ vfork();
int waitpid(scalar_t__, int *, int /*<<< orphan*/);
void vlogd(int bg, const char *cmd, const char *arg) {
  pid_t pid;
  pid = vfork();
  if (pid < 0)
    return;
  else if (pid == 0) {
    execl("/bin/logd", "/bin/logd", cmd, arg, NULL);
    _exit(1);
  } else if (!bg) {
    int status;
    while (waitpid(pid, &status, 0) == -1 && errno == EINTR)
      ;
  }
}


x86 assembly (clang, -O0):
<vlogd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <vfork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    116e <vlogd+0x2e>
jmp    120b <vlogd+0xcb>
cmpq   $0x0,-0x20(%rbp)
jne    119f <vlogd+0x5f>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe78(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1060 <execl@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1201 <vlogd+0xc1>
jmp    11ae <vlogd+0x6e>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x25(%rbp)
jne    11e7 <vlogd+0xa7>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11f7 <vlogd+0xb7>
jmp    11fc <vlogd+0xbc>
jmp    11ae <vlogd+0x6e>
jmp    1201 <vlogd+0xc1>
jmp    1206 <vlogd+0xc6>
jmp    120b <vlogd+0xcb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlogd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
js     119b <vlogd+0x5b>
je     11a6 <vlogd+0x66>
test   %ebp,%ebp
jne    119b <vlogd+0x5b>
mov    %rax,%rbx
lea    0x4(%rsp),%r14
mov    0x2e70(%rip),%r15
mov    0x2e61(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    119b <vlogd+0x5b>
mov    0x0(%rbp),%rax
cmp    %rax,(%r15)
je     1180 <vlogd+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe53(%rip),%rdi
mov    %rdi,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/bin/logd\00"
@errno = global i64 0
@EINTR = global i64 0
define void @vlogd(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = call i64 (...) @vfork()
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
br label %39
13: ; preds = %3
%14 = load i64, i64* %7
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i32* null)
%20 = call i32 @_exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %21
br label %25
25: ; preds = %35, %24
%26 = load i64, i64* %7
%27 = call i32 @waitpid(i64 %26, i32* %8, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i64, i64* @errno
%31 = load i64, i64* @EINTR
%32 = icmp eq i64 %30, %31
br label %33
33: ; preds = %29, %25
%34 = phi i1 [ false, %25 ], [ %32, %29 ]
br i1 %34, label %35, label %36
35: ; preds = %33
br label %25
36: ; preds = %33
br label %37
37: ; preds = %36, %21
br label %38
38: ; preds = %37
br label %39
39: ; preds = %12, %38
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bin/logd\00"
@errno = global i64 0
@EINTR = global i64 0
define void @vlogd(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = tail call i64 (...) @vfork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = icmp eq i64 %5, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i32* null)
%11 = tail call i32 @_exit(i32 1)
unreachable
12: ; preds = %7
%13 = icmp eq i32 %0, 0
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = bitcast i32* %4 to i8*
br label %16
16: ; preds = %16, %14
%17 = call i32 @waitpid(i64 %5, i32* %4, i32 0)
%18 = icmp eq i32 %17, -1
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
%22 = select i1 %18, i1 %21, i1 false
br i1 %22, label %16, label %23
23: ; preds = %16
br label %24
24: ; preds = %12, %23, %3
ret void
}