#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ ckpt_and_exit();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void *sbrk(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int num_tests = 0;
  int i, j;
  register int k;
  char buf[1024];
  FILE *fp;
  void *curbrk, *oldbrk;
  if (argc > 1) {
    num_tests = atoi(argv[1]);
  }
  if (!num_tests) {
    num_tests = 500;
  }
  if ((fp = fopen("job_ckpt_combo-sanity_std.results", "w")) == NULL) {
    perror("job_ckpt_combo-sanity_std.results");
    exit(1);
  }
  oldbrk = sbrk(0);
  for (i = 0; i < num_tests; i++) {
    sprintf(buf, "set i = %d\n", i);
    if (write(2, buf, strlen(buf)) == -1) {
      printf("WHAT?!? Write failed on fd[%d]\n", fileno(fp));
      exit(EXIT_FAILURE);
    }
    rewind(fp);
    if (fprintf(fp, "set i = %d\n", i) == -1) {
      printf("WHAT?!? fprintf failed on fd[%d]\n", fileno(fp));
      exit(EXIT_FAILURE);
    }
    fflush(fp);
    curbrk = sbrk(0);
    if (oldbrk != curbrk) {
      printf("Current break is now 0x%x, old was 0x%x (set i = %d)\n", curbrk,
             oldbrk, i);
    }
    oldbrk = curbrk;
    for (k = j = 0; j < 50000; k++, j++)
      ;
    if (j != k) {
      sprintf(buf, "j = %d, k (register) = %d\n", j, k);
      if (write(2, buf, strlen(buf)) == -1) {
        printf("WHAT?!? Write failed on fd[%d]\n", fileno(fp));
        exit(EXIT_FAILURE);
      }
    }
    ckpt_and_exit();
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    122a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123b <main+0x4b>
movl   $0x1f4,-0x14(%rbp)
lea    0xdbe(%rip),%rdi
lea    0xdd9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    1275 <main+0x85>
lea    0xd9a(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
xor    %edi,%edi
call   1080 <sbrk@plt>
mov    %rax,-0x438(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1498 <main+0x2a8>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1100 <sprintf@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    130e <main+0x11e>
mov    -0x428(%rbp),%rdi
call   10a0 <fileno@plt>
mov    %eax,%esi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x428(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x428(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xcf9(%rip),%rsi
call   1090 <fprintf@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x173>
mov    -0x428(%rbp),%rdi
call   10a0 <fileno@plt>
mov    %eax,%esi
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x428(%rbp),%rdi
call   10b0 <fflush@plt>
xor    %edi,%edi
call   1080 <sbrk@plt>
mov    %rax,-0x430(%rbp)
mov    -0x438(%rbp),%rax
cmp    -0x430(%rbp),%rax
je     13b2 <main+0x1c2>
mov    -0x430(%rbp),%rax
mov    %eax,%esi
mov    -0x438(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xc350,-0x1c(%rbp)
jge    13f7 <main+0x207>
jmp    13e0 <main+0x1f0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13ce <main+0x1de>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1483 <main+0x293>
lea    -0x420(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xc91(%rip),%rsi
mov    $0x0,%al
call   1100 <sprintf@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    147e <main+0x28e>
mov    -0x428(%rbp),%rdi
call   10a0 <fileno@plt>
mov    %eax,%esi
lea    0xbc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    1483 <main+0x293>
mov    $0x0,%al
call   10f0 <ckpt_and_exit@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    128a <main+0x9a>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x2,%edi
jl     1217 <main+0x27>
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jne    121f <main+0x2f>
movl   $0x1f4,0xc(%rsp)
lea    0xdda(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
jne    124d <main+0x5d>
lea    0xdc2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <sbrk@plt>
cmpl   $0x0,0xc(%rsp)
jle    130a <main+0x11a>
mov    %rax,%r14
lea    0xdb8(%rip),%r15
lea    0x10(%rsp),%r13
xor    %ebp,%ebp
jmp    1293 <main+0xa3>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10f0 <ckpt_and_exit@plt>
add    $0x1,%ebp
mov    %r12,%r14
cmp    %ebp,0xc(%rsp)
je     130a <main+0x11a>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    $0x2,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1319 <main+0x129>
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1090 <fprintf@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x13a>
mov    %rbx,%rdi
call   10b0 <fflush@plt>
xor    %edi,%edi
call   1080 <sbrk@plt>
mov    %rax,%r12
cmp    %rax,%r14
je     1280 <main+0x90>
lea    0xd7c(%rip),%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1280 <main+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    %rbx,%rdi
call   10a0 <fileno@plt>
lea    0xd08(%rip),%rdi
jmp    1339 <main+0x149>
mov    %rbx,%rdi
call   10a0 <fileno@plt>
lea    0xd17(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"job_ckpt_combo-sanity_std.results\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [12 x i8] c"set i = %d\0A\00"
@.str.3 = [32 x i8] c"WHAT?!? Write failed on fd[%d]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [34 x i8] c"WHAT?!? fprintf failed on fd[%d]\0A\00"
@.str.5 = [54 x i8] c"Current break is now 0x%x, old was 0x%x (set i = %d)\0A\00"
@.str.6 = [27 x i8] c"j = %d, k (register) = %d\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 i32
%10 = alloca [1024 x i8]
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
br label %21
21: ; preds = %16, %2
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %21
store i32 500, i32* %6
br label %25
25: ; preds = %24, %21
%26 = call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %11
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = call i8* @sbrk(i32 0)
store i8* %32, i8** %13
store i32 0, i32* %7
br label %33
33: ; preds = %112, %31
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %115
37: ; preds = %33
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @write(i32 2, i8* %41, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %52
46: ; preds = %37
%47 = load i32*, i32** %11
%48 = call i32 @fileno(i32* %47)
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %37
%53 = load i32*, i32** %11
%54 = call i32 @rewind(i32* %53)
%55 = load i32*, i32** %11
%56 = load i32, i32* %7
%57 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = load i32*, i32** %11
%61 = call i32 @fileno(i32* %60)
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %52
%66 = load i32*, i32** %11
%67 = call i32 @fflush(i32* %66)
%68 = call i8* @sbrk(i32 0)
store i8* %68, i8** %12
%69 = load i8*, i8** %13
%70 = load i8*, i8** %12
%71 = icmp ne i8* %69, %70
br i1 %71, label %72, label %78
72: ; preds = %65
%73 = load i8*, i8** %12
%74 = ptrtoint i8* %73 to i32
%75 = load i8*, i8** %13
%76 = load i32, i32* %7
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %74, i8* %75, i32 %76)
br label %78
78: ; preds = %72, %65
%79 = load i8*, i8** %12
store i8* %79, i8** %13
store i32 0, i32* %8
store i32 0, i32* %9
br label %80
80: ; preds = %84, %78
%81 = load i32, i32* %8
%82 = icmp slt i32 %81, 50000
br i1 %82, label %83, label %89
83: ; preds = %80
br label %84
84: ; preds = %83
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 1
store i32 %88, i32* %8
br label %80
89: ; preds = %80
%90 = load i32, i32* %8
%91 = load i32, i32* %9
%92 = icmp ne i32 %90, %91
br i1 %92, label %93, label %110
93: ; preds = %89
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%95 = load i32, i32* %8
%96 = load i32, i32* %9
%97 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %94, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %95, i32 %96)
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%100 = call i32 @strlen(i8* %99)
%101 = call i32 @write(i32 2, i8* %98, i32 %100)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %109
103: ; preds = %93
%104 = load i32*, i32** %11
%105 = call i32 @fileno(i32* %104)
%106 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %105)
%107 = load i32, i32* @EXIT_FAILURE
%108 = call i32 @exit(i32 %107)
unreachable
109: ; preds = %93
br label %110
110: ; preds = %109, %89
%111 = call i32 (...) @ckpt_and_exit()
br label %112
112: ; preds = %110
%113 = load i32, i32* %7
%114 = add nsw i32 %113, 1
store i32 %114, i32* %7
br label %33
115: ; preds = %33
%116 = load i32*, i32** %11
%117 = call i32 @fclose(i32* %116)
%118 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [34 x i8] c"job_ckpt_combo-sanity_std.results\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [12 x i8] c"set i = %d\0A\00"
@.str.3 = [32 x i8] c"WHAT?!? Write failed on fd[%d]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [34 x i8] c"WHAT?!? fprintf failed on fd[%d]\0A\00"
@.str.5 = [54 x i8] c"Current break is now 0x%x, old was 0x%x (set i = %d)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2, %6
br label %12
12: ; preds = %6, %11
%13 = phi i32 [ 500, %11 ], [ %9, %6 ]
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = tail call i8* @sbrk(i32 0)
%21 = icmp sgt i32 %13, 0
br i1 %21, label %22, label %55
22: ; preds = %19, %51
%23 = phi i8* [ %45, %51 ], [ %20, %19 ]
%24 = phi i32 [ %53, %51 ], [ 0, %19 ]
%25 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = call i32 @strlen(i8* %4)
%27 = call i32 @write(i32 2, i8* %4, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = call i32 @fileno(i32* %14)
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = call i32 @rewind(i32* %14)
%36 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = call i32 @fileno(i32* %14)
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = call i32 @fflush(i32* %14)
%45 = call i8* @sbrk(i32 0)
%46 = icmp eq i8* %23, %45
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = ptrtoint i8* %45 to i64
%49 = trunc i64 %48 to i32
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %49, i8* %23, i32 %24)
br label %51
51: ; preds = %43, %47
%52 = call i32 (...) @ckpt_and_exit()
%53 = add nuw nsw i32 %24, 1
%54 = icmp eq i32 %53, %13
br i1 %54, label %55, label %22
55: ; preds = %51, %19
%56 = call i32 @fclose(i32* %14)
%57 = call i32 @exit(i32 0)
unreachable
}