#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*/ time_t;

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int atoi(char *);
long long atoll(char *);
int /*<<< orphan*/ close(int);
scalar_t__ difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fsync(int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int, int);
int read(int, int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, int *, int);
int main(int argc, char **argv) {
  int exit_code, sleep_time, mem_kb;
  int i;
  long long int n;
  long long int file_size;
  int fd;
  char *mem;
  char *file_name;
  time_t time_start = time(NULL);
  if (argc != 6) {
    fprintf(stderr, "Usage: %s <exit_code> <sleep_time> <mem_kb> <file_size>\n",
            argv[0]);
    exit(1);
  }
  exit_code = atoi(argv[1]);
  sleep_time = atoi(argv[2]);
  mem_kb = atoi(argv[3]);
  file_size = atoll(argv[4]);
  file_name = argv[5];
  mem = malloc(mem_kb * 1024);
  memset(mem, 0, (mem_kb * 1024));
  fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  n = file_size / sizeof(int);
  for (i = 0; i < n; i++) {
    if (write(fd, &i, sizeof(int)) != sizeof(int)) {
      fprintf(stderr, "FAILURE: write error\n");
      exit(1);
    }
  }
  fsync(fd);
  close(fd);
  fd = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR);
  for (i = 0; i < n; i++) {
    if (read(fd, &i, sizeof(int)) != sizeof(int)) {
      fprintf(stderr, "FAILURE: read error\n");
      exit(1);
    }
  }
  close(fd);
  sleep_time -= difftime(time(NULL), time_start);
  sleep(sleep_time);
  free(mem);
  exit(exit_code);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     1244 <main+0x54>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoll@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
shl    $0xa,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
shl    $0xa,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
mov    0x2d33(%rip),%rax
or     (%rax),%esi
mov    0x2d22(%rip),%rax
or     (%rax),%esi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
mov    0x2cf0(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    135c <main+0x16c>
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cltq
cmp    $0x4,%rax
je     1349 <main+0x159>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    134e <main+0x15e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12fd <main+0x10d>
mov    -0x34(%rbp),%edi
call   10d0 <fsync@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    -0x48(%rbp),%rdi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
mov    0x2c38(%rip),%rax
mov    (%rax),%edx
mov    0x2c47(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    13f9 <main+0x209>
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
cltq
cmp    $0x4,%rax
je     13e6 <main+0x1f6>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    13eb <main+0x1fb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    139a <main+0x1aa>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
mov    -0x4c(%rbp),%esi
call   1050 <difftime@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1110 <sleep@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %edi,%edi
call   10b0 <time@plt>
cmp    $0x6,%ebx
jne    13b1 <main+0x1c1>
mov    %eax,0x10(%rsp)
mov    0x8(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    0x18(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
mov    0x20(%rbp),%rdi
call   1090 <atoll@plt>
mov    %rax,%r13
mov    0x28(%rbp),%rbp
shl    $0xa,%ebx
mov    %ebx,%edi
call   10c0 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    0x2d3a(%rip),%rax
mov    0x2d83(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d70(%rip),%rax
or     (%rax),%esi
mov    0x2d2f(%rip),%rax
mov    0x2d40(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,0x20(%rsp)
mov    %rbp,%rdi
call   10e0 <open@plt>
mov    %eax,%r14d
mov    %r13,%r12
shr    $0x2,%r12
movl   $0x0,0x8(%rsp)
cmp    $0x4,%r13
jb     12fc <main+0x10c>
cmp    $0x2,%r12
mov    $0x1,%ebx
cmovae %r12,%rbx
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
nopl   (%rax)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x4,%eax
jne    13d6 <main+0x1e6>
lea    0x1(%rbp),%rax
add    $0x1,%ebp
mov    %ebp,0x8(%rsp)
mov    %rax,%rbp
cmp    %rax,%rbx
jne    12d0 <main+0xe0>
mov    %r14d,%edi
call   10d0 <fsync@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
mov    0x2c93(%rip),%rax
or     (%rax),%edx
mov    0x20(%rsp),%rdi
call   10e0 <open@plt>
mov    %eax,%ebp
movl   $0x0,0x8(%rsp)
cmp    $0x4,%r13
jb     137a <main+0x18a>
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
cmp    $0x4,%eax
jne    13e8 <main+0x1f8>
movslq 0x8(%rsp),%rax
add    $0x1,%rax
mov    %eax,0x8(%rsp)
cmp    %rax,%r12
jg     1350 <main+0x160>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
mov    0x10(%rsp),%esi
call   1050 <difftime@plt>
mov    0xc(%rsp),%edi
sub    %eax,%edi
call   1110 <sleep@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%edi
call   1100 <exit@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc3b(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%edi
lea    0xc53(%rip),%rsi
jmp    13f8 <main+0x208>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc57(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Usage: %s <exit_code> <sleep_time> <mem_kb> <file_size>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [22 x i8] c"FAILURE: write error\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [21 x i8] c"FAILURE: read error\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 i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 @time(i32* null)
store i32 %16, i32* %15
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 6
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %8
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 4
%41 = load i8*, i8** %40
%42 = call i64 @atoll(i8* %41)
store i64 %42, i64* %11
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 5
%45 = load i8*, i8** %44
store i8* %45, i8** %14
%46 = load i32, i32* %8
%47 = mul nsw i32 %46, 1024
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %13
%49 = load i8*, i8** %13
%50 = load i32, i32* %8
%51 = mul nsw i32 %50, 1024
%52 = call i32 @memset(i8* %49, i32 0, i32 %51)
%53 = load i8*, i8** %14
%54 = load i32, i32* @O_WRONLY
%55 = load i32, i32* @O_CREAT
%56 = or i32 %54, %55
%57 = load i32, i32* @O_TRUNC
%58 = or i32 %56, %57
%59 = load i32, i32* @S_IRUSR
%60 = load i32, i32* @S_IWUSR
%61 = or i32 %59, %60
%62 = call i32 @open(i8* %53, i32 %58, i32 %61)
store i32 %62, i32* %12
%63 = load i64, i64* %11
%64 = udiv i64 %63, 4
store i64 %64, i64* %10
store i32 0, i32* %9
br label %65
65: ; preds = %80, %26
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = load i64, i64* %10
%69 = icmp slt i64 %67, %68
br i1 %69, label %70, label %83
70: ; preds = %65
%71 = load i32, i32* %12
%72 = call i32 @write(i32 %71, i32* %9, i32 4)
%73 = sext i32 %72 to i64
%74 = icmp ne i64 %73, 4
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %70
br label %80
80: ; preds = %79
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %65
83: ; preds = %65
%84 = load i32, i32* %12
%85 = call i32 @fsync(i32 %84)
%86 = load i32, i32* %12
%87 = call i32 @close(i32 %86)
%88 = load i8*, i8** %14
%89 = load i32, i32* @O_RDONLY
%90 = load i32, i32* @S_IRUSR
%91 = load i32, i32* @S_IWUSR
%92 = or i32 %90, %91
%93 = call i32 @open(i8* %88, i32 %89, i32 %92)
store i32 %93, i32* %12
store i32 0, i32* %9
br label %94
94: ; preds = %109, %83
%95 = load i32, i32* %9
%96 = sext i32 %95 to i64
%97 = load i64, i64* %10
%98 = icmp slt i64 %96, %97
br i1 %98, label %99, label %112
99: ; preds = %94
%100 = load i32, i32* %12
%101 = call i32 @read(i32 %100, i32* %9, i32 4)
%102 = sext i32 %101 to i64
%103 = icmp ne i64 %102, 4
br i1 %103, label %104, label %108
104: ; preds = %99
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %99
br label %109
109: ; preds = %108
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
store i32 %111, i32* %9
br label %94
112: ; preds = %94
%113 = load i32, i32* %12
%114 = call i32 @close(i32 %113)
%115 = call i32 @time(i32* null)
%116 = load i32, i32* %15
%117 = call i64 @difftime(i32 %115, i32 %116)
%118 = load i32, i32* %7
%119 = sext i32 %118 to i64
%120 = sub nsw i64 %119, %117
%121 = trunc i64 %120 to i32
store i32 %121, i32* %7
%122 = load i32, i32* %7
%123 = call i32 @sleep(i32 %122)
%124 = load i8*, i8** %13
%125 = call i32 @free(i8* %124)
%126 = load i32, i32* %6
%127 = call i32 @exit(i32 %126)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Usage: %s <exit_code> <sleep_time> <mem_kb> <file_size>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [22 x i8] c"FAILURE: write error\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [21 x i8] c"FAILURE: read error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = icmp eq i32 %0, 6
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
%24 = tail call i64 @atoll(i8* %23)
%25 = getelementptr inbounds i8*, i8** %1, i64 5
%26 = load i8*, i8** %25
%27 = shl nsw i32 %21, 10
%28 = tail call i8* @malloc(i32 %27)
%29 = tail call i32 @memset(i8* %28, i32 0, i32 %27)
%30 = load i32, i32* @O_WRONLY
%31 = load i32, i32* @O_CREAT
%32 = or i32 %31, %30
%33 = load i32, i32* @O_TRUNC
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %36, %35
%38 = tail call i32 @open(i8* %26, i32 %34, i32 %37)
%39 = lshr i64 %24, 2
store i32 0, i32* %3
%40 = icmp ult i64 %24, 4
br i1 %40, label %55, label %41
41: ; preds = %12
%42 = call i64 @llvm.umax.i64(i64 %39, i64 1)
br label %46
43: ; preds = %46
%44 = trunc i64 %50 to i32
store i32 %44, i32* %3
%45 = icmp eq i64 %50, %42
br i1 %45, label %55, label %46
46: ; preds = %41, %43
%47 = phi i64 [ 0, %41 ], [ %50, %43 ]
%48 = call i32 @write(i32 %38, i32* %3, i32 4)
%49 = icmp eq i32 %48, 4
%50 = add nuw nsw i64 %47, 1
br i1 %49, label %43, label %51
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %43, %12
%56 = tail call i32 @fsync(i32 %38)
%57 = tail call i32 @close(i32 %38)
%58 = load i32, i32* @O_RDONLY
%59 = load i32, i32* @S_IRUSR
%60 = load i32, i32* @S_IWUSR
%61 = or i32 %60, %59
%62 = tail call i32 @open(i8* %26, i32 %58, i32 %61)
store i32 0, i32* %3
br i1 %40, label %75, label %63
63: ; preds = %55, %70
%64 = call i32 @read(i32 %62, i32* %3, i32 4)
%65 = icmp eq i32 %64, 4
br i1 %65, label %70, label %66
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%69 = tail call i32 @exit(i32 1)
unreachable
70: ; preds = %63
%71 = load i32, i32* %3
%72 = add nsw i32 %71, 1
store i32 %72, i32* %3
%73 = sext i32 %72 to i64
%74 = icmp sgt i64 %39, %73
br i1 %74, label %63, label %75
75: ; preds = %70, %55
%76 = tail call i32 @close(i32 %62)
%77 = tail call i32 @time(i32* null)
%78 = tail call i64 @difftime(i32 %77, i32 %5)
%79 = trunc i64 %78 to i32
%80 = sub i32 %18, %79
%81 = tail call i32 @sleep(i32 %80)
%82 = tail call i32 @free(i8* %28)
%83 = tail call i32 @exit(i32 %15)
unreachable
}