#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 */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ closeall(int /*<<< orphan*/);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ log_message(int /*<<< orphan*/, char *);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ signal_handler_destroy();
int /*<<< orphan*/ system_call(char *);
int notify_exec(char *cmd) {
  pid_t pid;
  int ret;
  pid = fork();
  if (pid < 0) {
    log_message(LOG_INFO, "Failed fork process");
    return -1;
  }
  if (pid)
    return 0;
  signal_handler_destroy();
  closeall(0);
  open("/dev/null", O_RDWR);
  ret = dup(0);
  ret = dup(0);
  system_call(cmd);
  exit(0);
}


x86 assembly (clang, -O0):
<notify_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11c3 <notify_exec+0x43>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <notify_exec+0xa1>
cmpq   $0x0,-0x18(%rbp)
je     11da <notify_exec+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1221 <notify_exec+0xa1>
mov    $0x0,%al
call   1080 <signal_handler_destroy@plt>
xor    %edi,%edi
call   1060 <closeall@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1070 <open@plt>
xor    %edi,%edi
call   1040 <dup@plt>
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1040 <dup@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <system_call@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<notify_exec>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11d6 <notify_exec+0x56>
jne    11f0 <notify_exec+0x70>
xor    %eax,%eax
call   1080 <signal_handler_destroy@plt>
xor    %edi,%edi
call   1060 <closeall@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
call   1070 <open@plt>
xor    %edi,%edi
call   1040 <dup@plt>
xor    %edi,%edi
call   1040 <dup@plt>
mov    %rbx,%rdi
call   1030 <system_call@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
call   1050 <log_message@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [20 x i8] c"Failed fork process\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define i32 @notify_exec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @LOG_INFO
%11 = call i32 @log_message(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %26
12: ; preds = %1
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 0, i32* %2
br label %26
16: ; preds = %12
%17 = call i32 (...) @signal_handler_destroy()
%18 = call i32 @closeall(i32 0)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @dup(i32 0)
store i32 %21, i32* %5
%22 = call i32 @dup(i32 0)
store i32 %22, i32* %5
%23 = load i8*, i8** %3
%24 = call i32 @system_call(i8* %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %15, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [20 x i8] c"Failed fork process\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define i32 @notify_exec(i8* %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @LOG_INFO
%6 = tail call i32 @log_message(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %18
7: ; preds = %1
%8 = icmp eq i64 %2, 0
br i1 %8, label %9, label %18
9: ; preds = %7
%10 = tail call i32 (...) @signal_handler_destroy()
%11 = tail call i32 @closeall(i32 0)
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @dup(i32 0)
%15 = tail call i32 @dup(i32 0)
%16 = tail call i32 @system_call(i8* %0)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %7, %4
%19 = phi i32 [ -1, %4 ], [ 0, %7 ]
ret i32 %19
}