#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ _(char *);
int /*<<< orphan*/ execl(char const *, char const *, char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, int /*<<< orphan*/, char const *);
int waitpid(int, int *, int /*<<< orphan*/);
void merge_hook(const char *hookpath) {
  pid_t pid = fork();
  switch (pid) {
  case 0:
    execl(hookpath, hookpath, (char *)NULL);
    syslog(LOG_ERR, _("Cannot run \"%s\": %m"), hookpath);
    exit(1);
  case -1:
    syslog(LOG_ERR, _("Cannot run \"%s\": %m"), hookpath);
    break;
  default: {
    int status;
    while (waitpid(pid, &status, 0) != pid)
      ;
  }
  }
}


x86 assembly (clang, -O0):
<merge_hook>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11db <merge_hook+0x7b>
jmp    118a <merge_hook+0x2a>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    1206 <merge_hook+0xa6>
jmp    119a <merge_hook+0x3a>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execl@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe42(%rip),%rdi
call   1040 <_@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe12(%rip),%rdi
call   1040 <_@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1030 <syslog@plt>
jmp    122c <merge_hook+0xcc>
jmp    120b <merge_hook+0xab>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    -0xc(%rbp),%eax
je     1227 <merge_hook+0xc7>
jmp    120b <merge_hook+0xab>
jmp    122c <merge_hook+0xcc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_hook>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     1197 <merge_hook+0x37>
mov    %eax,%ebp
test   %eax,%eax
je     11be <merge_hook+0x5e>
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    %ebp,%eax
jne    1180 <merge_hook+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%ebp
lea    0xe59(%rip),%rdi
call   1040 <_@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <syslog@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <execl@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%ebp
lea    0xe25(%rip),%rdi
call   1040 <_@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [20 x i8] c"Cannot run \22%s\22: %m\00"
define void @merge_hook(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %21 [
i32 0, label %7
i32 -1, label %16
]
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @execl(i8* %8, i8* %9, i8* null)
%11 = load i32, i32* @LOG_ERR
%12 = call i32 @_(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i32 @syslog(i32 %11, i32 %12, i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i32, i32* @LOG_ERR
%18 = call i32 @_(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32 @syslog(i32 %17, i32 %18, i8* %19)
br label %29
21: ; preds = %1
br label %22
22: ; preds = %27, %21
%23 = load i32, i32* %3
%24 = call i32 @waitpid(i32 %23, i32* %4, i32 0)
%25 = load i32, i32* %3
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %22
br label %22
28: ; preds = %22
br label %29
29: ; preds = %28, %16
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [20 x i8] c"Cannot run \22%s\22: %m\00"
define void @merge_hook(i8* %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
switch i32 %3, label %14 [
i32 0, label %4
i32 -1, label %10
]
4: ; preds = %1
%5 = tail call i32 @execl(i8* %0, i8* %0, i8* null)
%6 = load i32, i32* @LOG_ERR
%7 = tail call i32 @_(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @syslog(i32 %6, i32 %7, i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32, i32* @LOG_ERR
%12 = tail call i32 @_(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @syslog(i32 %11, i32 %12, i8* %0)
br label %20
14: ; preds = %1
%15 = bitcast i32* %2 to i8*
br label %16
16: ; preds = %16, %14
%17 = call i32 @waitpid(i32 %3, i32* %2, i32 0)
%18 = icmp eq i32 %17, %3
br i1 %18, label %19, label %16
19: ; preds = %16
br label %20
20: ; preds = %19, %10
ret void
}