#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setCheckpointFile(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int /*<<< orphan*/ triggerCheckpoint();
int main(int argc, char **argv) {
  int j, unit, t;
  char *checkpointFileName;
  int checkpointUnit = 0;
  if (argc < 3) {
    fprintf(stderr, "Usage %s <checkpoint-file> <unit>\n", argv[0]);
    exit(1);
  }
  checkpointFileName = strdup(argv[1]);
  checkpointUnit = atoi(argv[2]);
  if (checkpointUnit < 1 || checkpointUnit > 100) {
    fprintf(stderr, "Checkpoint unit should be > 0 and < 100\n");
    exit(1);
  }
  printf("Checkpoint file: %s\n", checkpointFileName);
  printf("Checkpoint unit: %d\n", checkpointUnit);
  if (!setCheckpointFile(checkpointFileName)) {
    fprintf(stderr,
            "Error setting the checkpoint filename from within the process\n");
    fprintf(stderr, "Make sure you are running this program via mosrun\n");
    return 0;
  }
  for (unit = 0; unit < 100; unit++) {
    for (t = 0, j = 0; j < 1000000 * 500; j++) {
      t = j + unit * 2;
    }
    printf("Unit %d done\n", unit);
    if (unit == checkpointUnit) {
      if (!triggerCheckpoint())
        return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bf <main+0x4f>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     11f4 <main+0x84>
cmpl   $0x64,-0x2c(%rbp)
jle    1215 <main+0xa5>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <setCheckpointFile@plt>
cmp    $0x0,%eax
jne    1284 <main+0x114>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1324 <main+0x1b4>
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    131d <main+0x1ad>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1dcd6500,-0x14(%rbp)
jge    12cc <main+0x15c>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a3 <main+0x133>
mov    -0x18(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    130a <main+0x19a>
mov    $0x0,%al
call   1060 <triggerCheckpoint@plt>
cmp    $0x0,%eax
jne    1305 <main+0x195>
movl   $0x0,-0x4(%rbp)
jmp    1324 <main+0x1b4>
jmp    130a <main+0x19a>
jmp    130f <main+0x19f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    128b <main+0x11b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    1255 <main+0xe5>
mov    0x8(%rbx),%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
lea    -0x65(%r15),%eax
cmp    $0xffffff9b,%eax
jbe    1279 <main+0x109>
lea    0xe9d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1050 <setCheckpointFile@plt>
test   %eax,%eax
je     121d <main+0xad>
lea    0xf0b(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11f8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1216 <main+0xa6>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebp,%r15d
jne    11f0 <main+0x80>
xor    %eax,%eax
call   1060 <triggerCheckpoint@plt>
test   %eax,%eax
jne    11f0 <main+0x80>
jmp    1248 <main+0xd8>
mov    $0x1,%ebx
jmp    1248 <main+0xd8>
mov    0x2dbc(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe48(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd98(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage %s <checkpoint-file> <unit>\0A\00"
@.str.1 = [41 x i8] c"Checkpoint unit should be > 0 and < 100\0A\00"
@.str.2 = [21 x i8] c"Checkpoint file: %s\0A\00"
@.str.3 = [21 x i8] c"Checkpoint unit: %d\0A\00"
@.str.4 = [63 x i8] c"Error setting the checkpoint filename from within the process\0A\00"
@.str.5 = [51 x i8] c"Make sure you are running this program via mosrun\0A\00"
@.str.6 = [14 x i8] c"Unit %d done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %9
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %20
%32 = load i32, i32* %10
%33 = icmp sgt i32 %32, 100
br i1 %33, label %34, label %38
34: ; preds = %31, %20
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = load i8*, i8** %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %10
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %9
%44 = call i32 @setCheckpointFile(i8* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %83
51: ; preds = %38
store i32 0, i32* %7
br label %52
52: ; preds = %79, %51
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 100
br i1 %54, label %55, label %82
55: ; preds = %52
store i32 0, i32* %8
store i32 0, i32* %6
br label %56
56: ; preds = %64, %55
%57 = load i32, i32* %6
%58 = icmp slt i32 %57, 500000000
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = mul nsw i32 %61, 2
%63 = add nsw i32 %60, %62
store i32 %63, i32* %8
br label %64
64: ; preds = %59
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %56
67: ; preds = %56
%68 = load i32, i32* %7
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %7
%71 = load i32, i32* %10
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %78
73: ; preds = %67
%74 = call i32 (...) @triggerCheckpoint()
%75 = icmp ne i32 %74, 0
br i1 %75, label %77, label %76
76: ; preds = %73
store i32 0, i32* %3
br label %83
77: ; preds = %73
br label %78
78: ; preds = %77, %67
br label %79
79: ; preds = %78
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %52
82: ; preds = %52
store i32 1, i32* %3
br label %83
83: ; preds = %82, %76, %46
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage %s <checkpoint-file> <unit>\0A\00"
@.str.1 = [41 x i8] c"Checkpoint unit should be > 0 and < 100\0A\00"
@.str.2 = [21 x i8] c"Checkpoint file: %s\0A\00"
@.str.3 = [21 x i8] c"Checkpoint unit: %d\0A\00"
@.str.4 = [63 x i8] c"Error setting the checkpoint filename from within the process\0A\00"
@.str.5 = [51 x i8] c"Make sure you are running this program via mosrun\0A\00"
@.str.6 = [14 x i8] c"Unit %d done\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @strdup(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = add i32 %15, -101
%17 = icmp ult i32 %16, -100
br i1 %17, label %18, label %22
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %9
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%25 = tail call i32 @setCheckpointFile(i8* %12)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
br label %42
32: ; preds = %22, %39
%33 = phi i32 [ %40, %39 ], [ 0, %22 ]
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = icmp eq i32 %33, %15
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = tail call i32 (...) @triggerCheckpoint()
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %32, %36
%40 = add nuw nsw i32 %33, 1
%41 = icmp eq i32 %40, 100
br i1 %41, label %42, label %32
42: ; preds = %39, %36, %27
%43 = phi i32 [ 0, %27 ], [ 1, %39 ], [ 0, %36 ]
ret i32 %43
}