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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SHA1_Final(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, long *, int);
int SHA_DIGEST_LENGTH;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
long rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time();
int write(int, long *, int);
int main(int argc, char **argv) {
  int fd, length = 4 * 1024;
  void *memptr;
  long *long_array;
  int i;
  SHA_CTX context;
  char md[20];
  long randnum;
  if (argc != 3) {
    printf("USAGE: dump <filename> <size>\n");
    exit(-1);
  }
  printf("[DUMP] opening file %s\n", argv[1]);
  length = atoi(argv[2]) * 1024 * 1024;
  printf("[DUMP] size is %d\n", length);
  fd = open(argv[1], O_RDWR);
  srand(time());
  memset(md, 0, 20);
  SHA1_Init(&context);
  for (i = 0; i < length / sizeof(long); i++) {
    int n;
    randnum = rand();
    SHA1_Update(&context, &randnum, sizeof(long));
    n = write(fd, &randnum, sizeof(long));
    if (n < sizeof(long)) {
      printf("[ERROR] wrote %d bytes!\n", n);
    }
  }
  SHA1_Final(md, &context);
  close(fd);
  printf("[DUMP] ");
  for (i = 0; i < SHA_DIGEST_LENGTH; ++i) {
    unsigned char c = md[i];
    printf("%2.2x", c);
  }
  printf("\n");
  printf("munmap is unmapping %x\n", memptr);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     120f <main+0x3f>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
shl    $0xa,%eax
shl    $0xa,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
call   10a0 <SHA1_Init@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
movslq -0x18(%rbp),%rcx
shr    $0x3,%rcx
cmp    %rcx,%rax
jae    130b <main+0x13b>
mov    $0x0,%al
call   10f0 <rand@plt>
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x58(%rbp),%rsi
mov    $0x8,%edx
call   1090 <SHA1_Update@plt>
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x5c(%rbp)
movslq -0x5c(%rbp),%rax
cmp    $0x8,%rax
jae    12f8 <main+0x128>
mov    -0x5c(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fd <main+0x12d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1293 <main+0xc3>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10e0 <SHA1_Final@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2ca1(%rip),%rcx
cmp    (%rcx),%eax
jge    1372 <main+0x1a2>
movslq -0x2c(%rbp),%rax
mov    -0x50(%rbp,%rax,1),%al
mov    %al,-0x5d(%rbp)
movzbl -0x5d(%rbp),%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1335 <main+0x165>
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
cmp    $0x3,%edi
jne    1372 <main+0x182>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
mov    %eax,%ebp
shl    $0x14,%ebp
lea    0xde6(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10a0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    0x4(%rsp),%rdi
call   10c0 <SHA1_Init@plt>
test   %r14d,%r14d
je     12f5 <main+0x105>
movslq %ebp,%rax
shr    $0x3,%rax
cmp    $0x2,%rax
mov    $0x1,%ebx
cmovae %rax,%rbx
lea    0x4(%rsp),%r14
lea    0x8(%rsp),%rbp
lea    0xd88(%rip),%r15
jmp    12b6 <main+0xc6>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%rbx
je     12f5 <main+0x105>
xor    %eax,%eax
call   1110 <rand@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   10b0 <SHA1_Update@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1050 <write@plt>
cmp    $0x7,%eax
ja     12b0 <main+0xc0>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12b0 <main+0xc0>
lea    0x10(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1100 <SHA1_Final@plt>
mov    %r12d,%edi
call   1080 <close@plt>
lea    0xd31(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cbf(%rip),%r14
cmpl   $0x0,(%r14)
jle    134b <main+0x15b>
lea    0xd1e(%rip),%rbx
xor    %ebp,%ebp
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
movslq (%r14),%rax
cmp    %rax,%rbp
jl     1330 <main+0x140>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xcf6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf1(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"USAGE: dump <filename> <size>\0A\00"
@.str.1 = [24 x i8] c"[DUMP] opening file %s\0A\00"
@.str.2 = [19 x i8] c"[DUMP] size is %d\0A\00"
@O_RDWR = global i32 0
@.str.3 = [25 x i8] c"[ERROR] wrote %d bytes!\0A\00"
@.str.4 = [8 x i8] c"[DUMP] \00"
@SHA_DIGEST_LENGTH = global i32 0
@.str.5 = [6 x i8] c"%2.2x\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [24 x i8] c"munmap is unmapping %x\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 i8*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [20 x i8]
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4096, i32* %7
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
%30 = mul nsw i32 %29, 1024
%31 = mul nsw i32 %30, 1024
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %6
%39 = call i32 (...) @time()
%40 = call i32 @srand(i32 %39)
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 20)
%43 = call i32 @SHA1_Init(i32* %11)
store i32 0, i32* %10
br label %44
44: ; preds = %63, %21
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = udiv i64 %48, 8
%50 = icmp ult i64 %46, %49
br i1 %50, label %51, label %66
51: ; preds = %44
%52 = call i64 (...) @rand()
store i64 %52, i64* %13
%53 = call i32 @SHA1_Update(i32* %11, i64* %13, i32 8)
%54 = load i32, i32* %6
%55 = call i32 @write(i32 %54, i64* %13, i32 8)
store i32 %55, i32* %14
%56 = load i32, i32* %14
%57 = sext i32 %56 to i64
%58 = icmp ult i64 %57, 8
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i32, i32* %14
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %51
br label %63
63: ; preds = %62
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %44
66: ; preds = %44
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%68 = call i32 @SHA1_Final(i8* %67, i32* %11)
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %10
br label %72
72: ; preds = %84, %66
%73 = load i32, i32* %10
%74 = load i32, i32* @SHA_DIGEST_LENGTH
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %87
76: ; preds = %72
%77 = load i32, i32* %10
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 %78
%80 = load i8, i8* %79
store i8 %80, i8* %15
%81 = load i8, i8* %15
%82 = zext i8 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %76
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %72
87: ; preds = %72
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%89 = load i8*, i8** %8
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %89)
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"[DUMP] opening file %s\0A\00"
@.str.2 = [19 x i8] c"[DUMP] size is %d\0A\00"
@O_RDWR = global i32 0
@.str.3 = [25 x i8] c"[ERROR] wrote %d bytes!\0A\00"
@.str.4 = [8 x i8] c"[DUMP] \00"
@SHA_DIGEST_LENGTH = global i32 0
@.str.5 = [6 x i8] c"%2.2x\00"
@.str.7 = [24 x i8] c"munmap is unmapping %x\0A\00"
@str = [30 x i8] c"USAGE: dump <filename> <size>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = shl nsw i32 %19, 20
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %14
%23 = load i32, i32* @O_RDWR
%24 = tail call i32 @open(i8* %22, i32 %23)
%25 = tail call i32 (...) @time()
%26 = tail call i32 @srand(i32 %25)
%27 = call i32 @memset(i8* %7, i32 0, i32 20)
%28 = call i32 @SHA1_Init(i32* %3)
%29 = icmp eq i32 %19, 0
br i1 %29, label %45, label %30
30: ; preds = %13
%31 = sext i32 %20 to i64
%32 = lshr exact i64 %31, 3
%33 = call i64 @llvm.umax.i64(i64 %32, i64 1)
br label %34
34: ; preds = %30, %42
%35 = phi i64 [ 0, %30 ], [ %43, %42 ]
%36 = call i64 (...) @rand()
store i64 %36, i64* %5
%37 = call i32 @SHA1_Update(i32* %3, i64* %5, i32 8)
%38 = call i32 @write(i32 %24, i64* %5, i32 8)
%39 = icmp ult i32 %38, 8
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %42
42: ; preds = %40, %34
%43 = add nuw nsw i64 %35, 1
%44 = icmp eq i64 %43, %33
br i1 %44, label %45, label %34
45: ; preds = %42, %13
%46 = call i32 @SHA1_Final(i8* %7, i32* %3)
%47 = call i32 @close(i32 %24)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* @SHA_DIGEST_LENGTH
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %45, %51
%52 = phi i64 [ %57, %51 ], [ 0, %45 ]
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%57 = add nuw nsw i64 %52, 1
%58 = load i32, i32* @SHA_DIGEST_LENGTH
%59 = sext i32 %58 to i64
%60 = icmp slt i64 %57, %59
br i1 %60, label %51, label %61
61: ; preds = %51, %45
%62 = call i32 @putchar(i32 10)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* undef)
ret i32 0
}