#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*/ free(unsigned char *);
void *malloc(int);
int /*<<< orphan*/ memcpy(void *, unsigned char *, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ write_block(void *, unsigned char *);
int main(int argc, char *argv[]) {
  unsigned char *hash = malloc(16);
  void *block = malloc(32768);
  memset(block, 0, 32768);
  write_block(block, hash);
  for (int i = 0; i < 32768; i += 16)
    memcpy(block + i, hash, 16);
  write_block(block, hash);
  for (int i = 0; i < 32768; i += 16)
    memcpy(block + i, hash, 16);
  write_block(block, hash);
  for (int i = 0; i < 32768; i += 16)
    memcpy(block + i, hash, 16);
  write_block(block, hash);
  free(block);
  free(hash);
  return 0;
}


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)
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x8000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <write_block@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8000,-0x24(%rbp)
jge    11da <main+0x8a>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x56>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <write_block@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x8000,-0x28(%rbp)
jge    1222 <main+0xd2>
mov    -0x20(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <main+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <write_block@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x8000,-0x2c(%rbp)
jge    126a <main+0x11a>
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x2c(%rbp)
jmp    1236 <main+0xe6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <write_block@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x8000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_block@plt>
mov    $0xfffffffffffffff0,%rbx
lea    (%r15,%rbx,1),%rdi
add    $0x10,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x10,%rbx
cmp    $0x7ff0,%rbx
jb     1190 <main+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_block@plt>
mov    $0xfffffffffffffff0,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdi
add    $0x10,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x10,%rbx
cmp    $0x7ff0,%rbx
jb     11d0 <main+0x80>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_block@plt>
mov    $0xfffffffffffffff0,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdi
add    $0x10,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
add    $0x10,%rbx
cmp    $0x7ff0,%rbx
jb     1210 <main+0xc0>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <write_block@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @malloc(i32 16)
store i8* %11, i8** %6
%12 = call i8* @malloc(i32 32768)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = call i32 @memset(i8* %13, i32 0, i32 32768)
%15 = load i8*, i8** %7
%16 = load i8*, i8** %6
%17 = call i32 @write_block(i8* %15, i8* %16)
store i32 0, i32* %8
br label %18
18: ; preds = %28, %2
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 32768
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr i8, i8* %22, i64 %24
%26 = load i8*, i8** %6
%27 = call i32 @memcpy(i8* %25, i8* %26, i32 16)
br label %28
28: ; preds = %21
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 16
store i32 %30, i32* %8
br label %18
31: ; preds = %18
%32 = load i8*, i8** %7
%33 = load i8*, i8** %6
%34 = call i32 @write_block(i8* %32, i8* %33)
store i32 0, i32* %9
br label %35
35: ; preds = %45, %31
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 32768
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i8*, i8** %7
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr i8, i8* %39, i64 %41
%43 = load i8*, i8** %6
%44 = call i32 @memcpy(i8* %42, i8* %43, i32 16)
br label %45
45: ; preds = %38
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 16
store i32 %47, i32* %9
br label %35
48: ; preds = %35
%49 = load i8*, i8** %7
%50 = load i8*, i8** %6
%51 = call i32 @write_block(i8* %49, i8* %50)
store i32 0, i32* %10
br label %52
52: ; preds = %62, %48
%53 = load i32, i32* %10
%54 = icmp slt i32 %53, 32768
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i8*, i8** %7
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr i8, i8* %56, i64 %58
%60 = load i8*, i8** %6
%61 = call i32 @memcpy(i8* %59, i8* %60, i32 16)
br label %62
62: ; preds = %55
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 16
store i32 %64, i32* %10
br label %52
65: ; preds = %52
%66 = load i8*, i8** %7
%67 = load i8*, i8** %6
%68 = call i32 @write_block(i8* %66, i8* %67)
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %6
%72 = call i32 @free(i8* %71)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%4 = tail call dereferenceable_or_null(32768) i8* @malloc(i32 32768)
%5 = tail call i32 @memset(i8* %4, i32 0, i32 32768)
%6 = tail call i32 @write_block(i8* %4, i8* %3)
br label %9
7: ; preds = %9
%8 = tail call i32 @write_block(i8* %4, i8* %3)
br label %17
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %13, %9 ]
%11 = getelementptr i8, i8* %4, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %3, i32 16)
%13 = add nuw nsw i64 %10, 16
%14 = icmp ult i64 %10, 32752
br i1 %14, label %9, label %7
15: ; preds = %17
%16 = tail call i32 @write_block(i8* %4, i8* %3)
br label %27
17: ; preds = %7, %17
%18 = phi i64 [ 0, %7 ], [ %21, %17 ]
%19 = getelementptr i8, i8* %4, i64 %18
%20 = tail call i32 @memcpy(i8* %19, i8* %3, i32 16)
%21 = add nuw nsw i64 %18, 16
%22 = icmp ult i64 %18, 32752
br i1 %22, label %17, label %15
23: ; preds = %27
%24 = tail call i32 @write_block(i8* %4, i8* %3)
%25 = tail call i32 @free(i8* %4)
%26 = tail call i32 @free(i8* %3)
ret i32 0
27: ; preds = %15, %27
%28 = phi i64 [ 0, %15 ], [ %31, %27 ]
%29 = getelementptr i8, i8* %4, i64 %28
%30 = tail call i32 @memcpy(i8* %29, i8* %3, i32 16)
%31 = add nuw nsw i64 %28, 16
%32 = icmp ult i64 %28, 32752
br i1 %32, label %27, label %23
}