#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 /*<<< orphan*/ _spawn_job(char *, char **);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  char *command[10];
  int iterations, status;
  int i;
  if (argc != 5) {
    printf("FAILURE: Usage: test9.9.prog <sbatch_path> "
           "<exec_prog> <prog_name> <iterations>\n");
    exit(1);
  }
  iterations = atoi(argv[4]);
  if (iterations < 1) {
    printf("FAILURE: Invalid iterations count (%s)\n", argv[4]);
    exit(1);
  }
  command[0] = "sbatch";
  command[1] = "-J";
  command[2] = argv[3];
  command[3] = "-o";
  command[4] = "/dev/null";
  command[5] = "--wrap";
  command[6] = argv[2];
  command[7] = NULL;
  for (i = 0; i < iterations; i++) {
    _spawn_job(argv[1], command);
  }
  while ((wait(&status) >= 0))
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x1,-0x64(%rbp)
jge    11c2 <main+0x72>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xeb0(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xeac(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe8f(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    124b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <_spawn_job@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1220 <main+0xd0>
jmp    1250 <main+0x100>
lea    -0x68(%rbp),%rdi
call   1070 <wait@plt>
cmp    $0x0,%rax
jl     1268 <main+0x118>
jmp    1250 <main+0x100>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
cmp    $0x5,%edi
jne    1228 <main+0xc8>
mov    %rsi,%rbx
mov    0x20(%rsi),%r14
mov    %r14,%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    123e <main+0xde>
mov    %eax,%ebp
lea    0xe97(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe92(%rip),%rax
mov    %rax,0x18(%rsp)
mov    0x18(%rbx),%rax
mov    %rax,0x20(%rsp)
lea    0xe80(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe77(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe75(%rip),%rax
mov    %rax,0x38(%rsp)
mov    0x10(%rbx),%rax
mov    %rax,0x40(%rsp)
movq   $0x0,0x48(%rsp)
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1050 <_spawn_job@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x90>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <wait@plt>
test   %rax,%rax
jns    1210 <main+0xb0>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xdbb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [81 x i8] c"FAILURE: Usage: test9.9.prog <sbatch_path> <exec_prog> <prog_name> <iterations>\0A\00"
@.str.1 = [40 x i8] c"FAILURE: Invalid iterations count (%s)\0A\00"
@.str.2 = [7 x i8] c"sbatch\00"
@.str.3 = [3 x i8] c"-J\00"
@.str.4 = [3 x i8] c"-o\00"
@.str.5 = [10 x i8] c"/dev/null\00"
@.str.6 = [7 x i8] c"--wrap\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 5
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 4
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 4
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %15
%29 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %29
%30 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 2
store i8* %33, i8** %34
%35 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %35
%36 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 6
store i8* %40, i8** %41
%42 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 7
store i8* null, i8** %42
store i32 0, i32* %9
br label %43
43: ; preds = %53, %28
%44 = load i32, i32* %9
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 0
%52 = call i32 @_spawn_job(i8* %50, i8** %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %43
56: ; preds = %43
br label %57
57: ; preds = %60, %56
%58 = call i64 @wait(i32* %8)
%59 = icmp sge i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
br label %57
61: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"FAILURE: Invalid iterations count (%s)\0A\00"
@.str.2 = [7 x i8] c"sbatch\00"
@.str.3 = [3 x i8] c"-J\00"
@.str.4 = [3 x i8] c"-o\00"
@.str.5 = [10 x i8] c"/dev/null\00"
@.str.6 = [7 x i8] c"--wrap\00"
@str = [80 x i8] c"FAILURE: Usage: test9.9.prog <sbatch_path> <exec_prog> <prog_name> <iterations>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8*]
%4 = alloca i32
%5 = bitcast [10 x i8*]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 5
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 4
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 2
store i8* %23, i8** %24
%25 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %25
%26 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 6
store i8* %29, i8** %30
%31 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 7
store i8* null, i8** %31
%32 = getelementptr inbounds i8*, i8** %1, i64 1
br label %33
33: ; preds = %19, %33
%34 = phi i32 [ 0, %19 ], [ %37, %33 ]
%35 = load i8*, i8** %32
%36 = call i32 @_spawn_job(i8* %35, i8** %20)
%37 = add nuw nsw i32 %34, 1
%38 = icmp eq i32 %37, %14
br i1 %38, label %39, label %33
39: ; preds = %33, %39
%40 = call i64 @wait(i32* %4)
%41 = icmp sgt i64 %40, -1
br i1 %41, label %39, label %42
42: ; preds = %39
ret i32 0
}