#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 */
struct string {
  int dummy;
};
struct graph_node {
  int dummy;
};
struct dict {
  int dummy;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char *, char const *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ expand_macros(struct string *, struct dict *, struct string *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ populate_automatic_macros(struct graph_node *,
                                             struct dict *);
int /*<<< orphan*/ puts(char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ string_destroy(struct string *);
char *string_get_cstr(struct string *);
struct string *string_init(char *);
pid_t start_job(struct graph_node *node, struct string *command,
                struct dict *macros, int *ignore_errors) {
  struct string *expanded = string_init("");
  int echo = 1;
  const char *cstr;
  pid_t pid;
  populate_automatic_macros(node, macros);
  if (expand_macros(command, macros, expanded)) {
    string_destroy(expanded);
    return (-1);
  }
  cstr = string_get_cstr(expanded);
  *ignore_errors = 0;
  while (*cstr == '@' || *cstr == '-' || *cstr == '+') {
    if (*cstr == '@') {
      echo = 0;
    } else if (*cstr == '-') {
      *ignore_errors = 1;
    }
    ++cstr;
  }
  if (echo) {
    puts(cstr);
    fflush(stdout);
  }
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "fork call failed\n");
    string_destroy(expanded);
    return (-1);
  } else if (pid == 0) {
    execl("/bin/sh", "sh", "-ce", cstr, NULL);
    fprintf(stderr, "exec call failed\n");
    exit(1);
  }
  string_destroy(expanded);
  return (pid);
}


x86 assembly (clang, -O0):
<start_job>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <populate_automatic_macros@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1090 <expand_macros@plt>
cmp    $0x0,%rax
je     121c <start_job+0x6c>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1388 <start_job+0x1d8>
mov    -0x30(%rbp),%rdi
call   10a0 <string_get_cstr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x40(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x40,%ecx
mov    %al,-0x45(%rbp)
je     126d <start_job+0xbd>
mov    -0x40(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2d,%ecx
mov    %al,-0x45(%rbp)
je     126d <start_job+0xbd>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
sete   %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    127d <start_job+0xcd>
jmp    12c9 <start_job+0x119>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1299 <start_job+0xe9>
movl   $0x0,-0x34(%rbp)
jmp    12b8 <start_job+0x108>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12b3 <start_job+0x103>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    12b8 <start_job+0x108>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1233 <start_job+0x83>
cmpl   $0x0,-0x34(%rbp)
je     12ea <start_job+0x13a>
mov    -0x40(%rbp),%rdi
call   1030 <puts@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1328 <start_job+0x178>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xcf2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1388 <start_job+0x1d8>
cmpl   $0x0,-0x44(%rbp)
jne    1374 <start_job+0x1c4>
mov    -0x40(%rbp),%rcx
lea    0xcd5(%rip),%rdi
lea    0xcd3(%rip),%rsi
lea    0xccf(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <execl@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xcb9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1379 <start_job+0x1c9>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_job>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe64(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <populate_automatic_macros@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1090 <expand_macros@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    12c3 <start_job+0x113>
mov    %r15,%rdi
call   10a0 <string_get_cstr@plt>
mov    %rax,%rbp
movl   $0x0,(%rbx)
mov    $0x1,%eax
jmp    1228 <start_job+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ecx
add    $0x1,%rbp
mov    %ecx,%eax
movzbl 0x0(%rbp),%edx
cmp    $0x2b,%dl
je     1220 <start_job+0x70>
xor    %ecx,%ecx
cmp    $0x40,%dl
je     1222 <start_job+0x72>
cmp    $0x2d,%dl
jne    1245 <start_job+0x95>
movl   $0x1,(%rbx)
jmp    1220 <start_job+0x70>
test   %eax,%eax
je     125f <start_job+0xaf>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
js     12ae <start_job+0xfe>
mov    %eax,%r14d
jne    12c3 <start_job+0x113>
lea    0xd9c(%rip),%rdi
lea    0xd9a(%rip),%rsi
lea    0xd96(%rip),%rdx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   10c0 <execl@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1050 <string_destroy@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.graph_node = type { i32 }
%struct.string = type { i32 }
%struct.dict = type { i32 }
@.str = [1 x i8] zeroinitializer
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"fork call failed\0A\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [4 x i8] c"-ce\00"
@.str.5 = [18 x i8] c"exec call failed\0A\00"
define i32 @start_job(%struct.graph_node* %0, %struct.string* %1, %struct.dict* %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.graph_node*
%7 = alloca %struct.string*
%8 = alloca %struct.dict*
%9 = alloca i32*
%10 = alloca %struct.string*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store %struct.graph_node* %0, %struct.graph_node** %6
store %struct.string* %1, %struct.string** %7
store %struct.dict* %2, %struct.dict** %8
store i32* %3, i32** %9
%14 = call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store %struct.string* %14, %struct.string** %10
store i32 1, i32* %11
%15 = load %struct.graph_node*, %struct.graph_node** %6
%16 = load %struct.dict*, %struct.dict** %8
%17 = call i32 @populate_automatic_macros(%struct.graph_node* %15, %struct.dict* %16)
%18 = load %struct.string*, %struct.string** %7
%19 = load %struct.dict*, %struct.dict** %8
%20 = load %struct.string*, %struct.string** %10
%21 = call i64 @expand_macros(%struct.string* %18, %struct.dict* %19, %struct.string* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %4
%24 = load %struct.string*, %struct.string** %10
%25 = call i32 @string_destroy(%struct.string* %24)
store i32 -1, i32* %5
br label %95
26: ; preds = %4
%27 = load %struct.string*, %struct.string** %10
%28 = call i8* @string_get_cstr(%struct.string* %27)
store i8* %28, i8** %12
%29 = load i32*, i32** %9
store i32 0, i32* %29
br label %30
30: ; preds = %61, %26
%31 = load i8*, i8** %12
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 64
br i1 %34, label %45, label %35
35: ; preds = %30
%36 = load i8*, i8** %12
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 45
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = load i8*, i8** %12
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 43
br label %45
45: ; preds = %40, %35, %30
%46 = phi i1 [ true, %35 ], [ true, %30 ], [ %44, %40 ]
br i1 %46, label %47, label %64
47: ; preds = %45
%48 = load i8*, i8** %12
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 64
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 0, i32* %11
br label %61
53: ; preds = %47
%54 = load i8*, i8** %12
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 45
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = load i32*, i32** %9
store i32 1, i32* %59
br label %60
60: ; preds = %58, %53
br label %61
61: ; preds = %60, %52
%62 = load i8*, i8** %12
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %12
br label %30
64: ; preds = %45
%65 = load i32, i32* %11
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i8*, i8** %12
%69 = call i32 @puts(i8* %68)
%70 = load i32, i32* @stdout
%71 = call i32 @fflush(i32 %70)
br label %72
72: ; preds = %67, %64
%73 = call i32 (...) @fork()
store i32 %73, i32* %13
%74 = load i32, i32* %13
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %72
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%79 = load %struct.string*, %struct.string** %10
%80 = call i32 @string_destroy(%struct.string* %79)
store i32 -1, i32* %5
br label %95
81: ; preds = %72
%82 = load i32, i32* %13
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %81
%85 = load i8*, i8** %12
%86 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %85, i32* null)
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %81
br label %91
91: ; preds = %90
%92 = load %struct.string*, %struct.string** %10
%93 = call i32 @string_destroy(%struct.string* %92)
%94 = load i32, i32* %13
store i32 %94, i32* %5
br label %95
95: ; preds = %91, %76, %23
%96 = load i32, i32* %5
ret i32 %96
}

LLVM IR (-O2):
%struct.graph_node = type { i32 }
%struct.string = type { i32 }
%struct.dict = type { i32 }
@.str = [1 x i8] zeroinitializer
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"fork call failed\0A\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [4 x i8] c"-ce\00"
@.str.5 = [18 x i8] c"exec call failed\0A\00"
define i32 @start_job(%struct.graph_node* %0, %struct.string* %1, %struct.dict* %2, i32* nocapture writeonly %3) {
%5 = tail call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @populate_automatic_macros(%struct.graph_node* %0, %struct.dict* %2)
%7 = tail call i64 @expand_macros(%struct.string* %1, %struct.dict* %2, %struct.string* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %39
9: ; preds = %4
%10 = tail call i8* @string_get_cstr(%struct.string* %5)
store i32 0, i32* %3
br label %11
11: ; preds = %17, %9
%12 = phi i32 [ 1, %9 ], [ %18, %17 ]
%13 = phi i8* [ %10, %9 ], [ %19, %17 ]
%14 = load i8, i8* %13
switch i8 %14, label %20 [
i8 64, label %17
i8 45, label %15
i8 43, label %16
]
15: ; preds = %11
store i32 1, i32* %3
br label %17
16: ; preds = %11
br label %17
17: ; preds = %11, %16, %15
%18 = phi i32 [ %12, %15 ], [ %12, %16 ], [ 0, %11 ]
%19 = getelementptr inbounds i8, i8* %13, i64 1
br label %11
20: ; preds = %11
%21 = icmp eq i32 %12, 0
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = tail call i32 @puts(i8* %13)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
br label %26
26: ; preds = %22, %20
%27 = tail call i32 (...) @fork()
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %39
32: ; preds = %26
%33 = icmp eq i32 %27, 0
br i1 %33, label %34, label %39
34: ; preds = %32
%35 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %13, i32* null)
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %32, %4, %29
%40 = phi i32 [ -1, %29 ], [ -1, %4 ], [ %27, %32 ]
%41 = tail call i32 @string_destroy(%struct.string* %5)
ret i32 %40
}