#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 EXIT_SUCCESS;
scalar_t__ chdir(char const *);
int /*<<< orphan*/ nxweb_die(char *);
int /*<<< orphan*/ nxweb_open_log_file(char const *);
int nxweb_run_normal(const char *work_dir, const char *log_file,
                     const char *pid_file, void (*main_func)()) {
  if (work_dir && chdir(work_dir) < 0) {
    nxweb_die("chdir(work_dir) failed");
  }
  if (log_file)
    nxweb_open_log_file(log_file);
  main_func();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<nxweb_run_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1172 <nxweb_run_normal+0x42>
mov    -0x8(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    1172 <nxweb_run_normal+0x42>
lea    0xe93(%rip),%rdi
call   1040 <nxweb_die@plt>
cmpq   $0x0,-0x10(%rbp)
je     1186 <nxweb_run_normal+0x56>
mov    -0x10(%rbp),%rdi
call   1050 <nxweb_open_log_file@plt>
mov    $0x0,%al
call   *-0x20(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nxweb_run_normal>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
test   %rdi,%rdi
je     1149 <nxweb_run_normal+0x19>
call   1030 <chdir@plt>
test   %rax,%rax
js     116c <nxweb_run_normal+0x3c>
test   %rbx,%rbx
je     1156 <nxweb_run_normal+0x26>
mov    %rbx,%rdi
call   1050 <nxweb_open_log_file@plt>
xor    %eax,%eax
call   *%r14
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8d(%rip),%rdi
call   1040 <nxweb_die@plt>
test   %rbx,%rbx
jne    114e <nxweb_run_normal+0x1e>
jmp    1156 <nxweb_run_normal+0x26>

LLVM IR (-O0):
@.str = [23 x i8] c"chdir(work_dir) failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @nxweb_run_normal(i8* %0, i8* %1, i8* %2, void (...)* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca void (...)*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store void (...)* %3, void (...)** %8
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = load i8*, i8** %5
%13 = call i64 @chdir(i8* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @nxweb_die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11, %4
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = call i32 @nxweb_open_log_file(i8* %21)
br label %23
23: ; preds = %20, %17
%24 = load void (...)*, void (...)** %8
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}

LLVM IR (-O2):
@.str = [23 x i8] c"chdir(work_dir) failed\00"
@EXIT_SUCCESS = global i32 0
define i32 @nxweb_run_normal(i8* %0, i8* %1, i8* nocapture readnone %2, void (...)* nocapture %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = tail call i64 @chdir(i8* %0)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @nxweb_die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6, %4
%12 = icmp eq i8* %1, null
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @nxweb_open_log_file(i8* %1)
br label %15
15: ; preds = %13, %11
tail call void (...) %3()
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}