#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*/ WIFEXITED(int);
scalar_t__ fork_actual_command(int, unsigned short, char *, char *);
scalar_t__ fork_llstat_command(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_path_stats(int, char *);
int /*<<< orphan*/ kill(scalar_t__, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void fork_command(int type, unsigned short id, char *command,
                  char *llstat_file) {
  pid_t pid_actual_command = 0;
  pid_t pid_llstat_command = 0;
  int with_llstat = 1;
  int status;
  char stats_path[1024];
  char stats_path_temp[1024];
  if (strlen(llstat_file) == 0)
    with_llstat = 0;
  get_path_stats(with_llstat, stats_path);
  strcpy(stats_path_temp, stats_path);
  if (with_llstat)
    pid_llstat_command = fork_llstat_command(llstat_file, stats_path_temp);
  pid_actual_command = fork_actual_command(type, id, stats_path, command);
  if (waitpid(pid_actual_command, NULL, 0) != pid_actual_command)
    fprintf(stderr, "Error: waitpid error\n");
  if (with_llstat) {
    sleep(2);
    kill(pid_llstat_command, 9);
    waitpid(pid_llstat_command, &status, 0);
    if (!WIFEXITED(status))
      printf("\n\t[Note: Do \"$plot-llstat %s\" to plot a graph"
             " using GNU plot]\n",
             llstat_file);
  }
}


x86 assembly (clang, -O0):
<fork_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    11fe <fork_command+0x4e>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x430(%rbp),%rsi
call   10b0 <get_path_stats@plt>
lea    -0x830(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x0,-0x2c(%rbp)
je     123e <fork_command+0x8e>
mov    -0x18(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1030 <fork_llstat_command@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x6(%rbp),%ax
lea    -0x430(%rbp),%rdx
mov    -0x10(%rbp),%rcx
movzwl %ax,%esi
call   10a0 <fork_actual_command@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
cmp    -0x20(%rbp),%rax
je     128a <fork_command+0xda>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1070 <fprintf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     12e1 <fork_command+0x131>
mov    $0x2,%edi
call   10d0 <sleep@plt>
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   1080 <kill@plt>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x30(%rbp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    12dc <fork_command+0x12c>
mov    -0x18(%rbp),%rsi
lea    0xd3f(%rip),%rdi
call   1060 <printf@plt>
jmp    12e1 <fork_command+0x131>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %esi,%r15d
mov    %edi,%r13d
mov    (%rcx),%r14b
xor    %edi,%edi
test   %r14b,%r14b
setne  %dil
lea    0x410(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <get_path_stats@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
test   %r14b,%r14b
mov    %rbp,0x8(%rsp)
je     1202 <fork_command+0x62>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   1030 <fork_llstat_command@plt>
mov    %rax,%rbp
jmp    1204 <fork_command+0x64>
xor    %ebp,%ebp
movzwl %r15w,%esi
lea    0x410(%rsp),%rdx
mov    %r13d,%edi
mov    %r12,%rcx
call   1090 <fork_actual_command@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    %rbx,%rax
je     1244 <fork_command+0xa4>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
test   %r14b,%r14b
je     128d <fork_command+0xed>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    %rbp,%rdi
mov    $0x9,%esi
call   1070 <kill@plt>
lea    0x4(%rsp),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    0x4(%rsp),%edi
call   10b0 <WIFEXITED@plt>
test   %eax,%eax
jne    128d <fork_command+0xed>
lea    0xd93(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1050 <printf@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Error: waitpid error\0A\00"
@.str.1 = [63 x i8] c"\0A\09[Note: Do \22$plot-llstat %s\22 to plot a graph using GNU plot]\0A\00"
define void @fork_command(i32 %0, i16 zeroext %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
store i32 %0, i32* %5
store i16 %1, i16* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i64 0, i64* %9
store i64 0, i64* %10
store i32 1, i32* %11
%15 = load i8*, i8** %8
%16 = call i64 @strlen(i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %11
br label %19
19: ; preds = %18, %4
%20 = load i32, i32* %11
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%22 = call i32 @get_path_stats(i32 %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i32, i32* %11
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i8*, i8** %8
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%31 = call i64 @fork_llstat_command(i8* %29, i8* %30)
store i64 %31, i64* %10
br label %32
32: ; preds = %28, %19
%33 = load i32, i32* %5
%34 = load i16, i16* %6
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%36 = load i8*, i8** %7
%37 = call i64 @fork_actual_command(i32 %33, i16 zeroext %34, i8* %35, i8* %36)
store i64 %37, i64* %9
%38 = load i64, i64* %9
%39 = call i64 @waitpid(i64 %38, i32* null, i32 0)
%40 = load i64, i64* %9
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %32
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %42, %32
%46 = load i32, i32* %11
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = call i32 @sleep(i32 2)
%50 = load i64, i64* %10
%51 = call i32 @kill(i64 %50, i32 9)
%52 = load i64, i64* %10
%53 = call i64 @waitpid(i64 %52, i32* %12, i32 0)
%54 = load i32, i32* %12
%55 = call i32 @WIFEXITED(i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %48
%58 = load i8*, i8** %8
%59 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %57, %48
br label %61
61: ; preds = %60, %45
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Error: waitpid error\0A\00"
@.str.1 = [63 x i8] c"\0A\09[Note: Do \22$plot-llstat %s\22 to plot a graph using GNU plot]\0A\00"
define void @fork_command(i32 %0, i16 zeroext %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = call i32 @get_path_stats(i32 %14, i8* %9)
%16 = call i32 @strcpy(i8* %10, i8* %9)
br i1 %12, label %19, label %17
17: ; preds = %4
%18 = call i64 @fork_llstat_command(i8* %3, i8* %10)
br label %19
19: ; preds = %17, %4
%20 = phi i64 [ %18, %17 ], [ 0, %4 ]
%21 = call i64 @fork_actual_command(i32 %0, i16 zeroext %1, i8* %9, i8* %2)
%22 = call i64 @waitpid(i64 %21, i32* null, i32 0)
%23 = icmp eq i64 %22, %21
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %24, %19
br i1 %12, label %37, label %28
28: ; preds = %27
%29 = call i32 @sleep(i32 2)
%30 = call i32 @kill(i64 %20, i32 9)
%31 = call i64 @waitpid(i64 %20, i32* %5, i32 0)
%32 = load i32, i32* %5
%33 = call i32 @WIFEXITED(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %37
37: ; preds = %28, %35, %27
ret void
}