#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 execute_file();
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ is_exit_flag();
int /*<<< orphan*/ monitor_args_executed();
int /*<<< orphan*/ monitor_args_wait_executable();
int /*<<< orphan*/ set_exit_flag(int);
int /*<<< orphan*/ stderr;
void *cmd_exec_start(void *arg) {
  for (;;) {
    monitor_args_wait_executable();
    if (is_exit_flag())
      break;
    if (execute_file() == -1) {
      set_exit_flag(1);
      fflush(stderr);
      monitor_args_executed();
      return (void *)1;
    }
    monitor_args_executed();
  }
  return 0;
}


x86 assembly (clang, -O0):
<cmd_exec_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <monitor_args_wait_executable@plt>
mov    $0x0,%al
call   1040 <is_exit_flag@plt>
cmp    $0x0,%rax
je     1189 <cmd_exec_start+0x29>
jmp    11d2 <cmd_exec_start+0x72>
mov    $0x0,%al
call   1080 <execute_file@plt>
cmp    $0xffffffff,%eax
jne    11c6 <cmd_exec_start+0x66>
mov    $0x1,%edi
call   1050 <set_exit_flag@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x0,%al
call   1060 <monitor_args_executed@plt>
mov    $0x1,%eax
mov    %rax,-0x8(%rbp)
jmp    11da <cmd_exec_start+0x7a>
mov    $0x0,%al
call   1060 <monitor_args_executed@plt>
jmp    116c <cmd_exec_start+0xc>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_exec_start>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <monitor_args_wait_executable@plt>
xor    %eax,%eax
call   1040 <is_exit_flag@plt>
test   %rax,%rax
jne    11cc <cmd_exec_start+0x6c>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <execute_file@plt>
cmp    $0xffffffff,%eax
je     11a8 <cmd_exec_start+0x48>
xor    %eax,%eax
call   1060 <monitor_args_executed@plt>
xor    %eax,%eax
call   1030 <monitor_args_wait_executable@plt>
xor    %eax,%eax
call   1040 <is_exit_flag@plt>
test   %rax,%rax
je     1180 <cmd_exec_start+0x20>
jmp    11cc <cmd_exec_start+0x6c>
mov    $0x1,%edi
call   1050 <set_exit_flag@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %eax,%eax
call   1060 <monitor_args_executed@plt>
mov    $0x1,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
define i8* @cmd_exec_start(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
br label %4
4: ; preds = %17, %1
%5 = call i32 (...) @monitor_args_wait_executable()
%6 = call i64 (...) @is_exit_flag()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %19
9: ; preds = %4
%10 = call i32 (...) @execute_file()
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = call i32 @set_exit_flag(i32 1)
%14 = load i32, i32* @stderr
%15 = call i32 @fflush(i32 %14)
%16 = call i32 (...) @monitor_args_executed()
store i8* inttoptr (i64 1 to i8*), i8** %2
br label %20
17: ; preds = %9
%18 = call i32 (...) @monitor_args_executed()
br label %4
19: ; preds = %8
store i8* null, i8** %2
br label %20
20: ; preds = %19, %12
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
define i8* @cmd_exec_start(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @monitor_args_wait_executable()
%3 = tail call i64 (...) @is_exit_flag()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1, %13
%6 = tail call i32 (...) @execute_file()
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @set_exit_flag(i32 1)
%10 = load i32, i32* @stderr
%11 = tail call i32 @fflush(i32 %10)
%12 = tail call i32 (...) @monitor_args_executed()
br label %18
13: ; preds = %5
%14 = tail call i32 (...) @monitor_args_executed()
%15 = tail call i32 (...) @monitor_args_wait_executable()
%16 = tail call i64 (...) @is_exit_flag()
%17 = icmp eq i64 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %13, %1, %8
%19 = phi i8* [ inttoptr (i64 1 to i8*), %8 ], [ null, %1 ], [ null, %13 ]
ret i8* %19
}