#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*/ calculate_result(int, int, unsigned long);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ flush();
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
unsigned long mytime();
int /*<<< orphan*/ newline();
int /*<<< orphan*/ print(char *);
void library_test() {
  char *a1, *a2;
  unsigned long t, t0;
  int i;
  a1 = malloc((64 * 1024 * 1024));
  if (!a1)
    error("Out of memory");
  a2 = malloc((64 * 1024 * 1024));
  if (!a2)
    error("Out of memory");
  t0 = mytime();
  for (i = 0; i < (100); i++) {
    memset(a1, i, (64 * 1024 * 1024));
  }
  t = mytime();
  print("Library: memset ");
  calculate_result((64 * 1024 * 1024), (100), t - t0);
  newline();
  flush();
  t0 = mytime();
  for (i = 0; i < (100); i++) {
    memcpy(a2, a1, (64 * 1024 * 1024));
  }
  t = mytime();
  print("Library: memcpy ");
  calculate_result((64 * 1024 * 1024), (100), t - t0);
  newline();
  flush();
  free(a1);
  free(a2);
}


x86 assembly (clang, -O0):
<library_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x4000000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11cd <library_test+0x2d>
lea    0xe38(%rip),%rdi
call   10a0 <error@plt>
mov    $0x4000000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f2 <library_test+0x52>
lea    0xe13(%rip),%rdi
call   10a0 <error@plt>
mov    $0x0,%al
call   10b0 <mytime@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    122d <library_test+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0x4000000,%edx
call   1060 <memset@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1204 <library_test+0x64>
mov    $0x0,%al
call   10b0 <mytime@plt>
mov    %rax,-0x18(%rbp)
lea    0xdcf(%rip),%rdi
call   1070 <print@plt>
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
mov    $0x4000000,%edi
mov    $0x64,%esi
call   10c0 <calculate_result@plt>
mov    $0x0,%al
call   1040 <newline@plt>
mov    $0x0,%al
call   1050 <flush@plt>
mov    $0x0,%al
call   10b0 <mytime@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    12a5 <library_test+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4000000,%edx
call   1080 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127b <library_test+0xdb>
mov    $0x0,%al
call   10b0 <mytime@plt>
mov    %rax,-0x18(%rbp)
lea    0xd68(%rip),%rdi
call   1070 <print@plt>
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
mov    $0x4000000,%edi
mov    $0x64,%esi
call   10c0 <calculate_result@plt>
mov    $0x0,%al
call   1040 <newline@plt>
mov    $0x0,%al
call   1050 <flush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<library_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x4000000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c6 <library_test+0x26>
lea    0xe3f(%rip),%rdi
call   10a0 <error@plt>
mov    $0x4000000,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11e4 <library_test+0x44>
lea    0xe21(%rip),%rdi
call   10a0 <error@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <mytime@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x4000000,%edx
call   1060 <memset@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    11f0 <library_test+0x50>
xor    %eax,%eax
call   10b0 <mytime@plt>
mov    %rax,%r12
lea    0xdf6(%rip),%rdi
call   1070 <print@plt>
sub    %r15,%r12
mov    $0x64,%ebp
mov    $0x4000000,%edi
mov    $0x64,%esi
mov    %r12,%rdx
call   10c0 <calculate_result@plt>
xor    %eax,%eax
call   1040 <newline@plt>
xor    %eax,%eax
call   1050 <flush@plt>
xor    %eax,%eax
call   10b0 <mytime@plt>
mov    %rax,%r15
nop
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4000000,%edx
call   1080 <memcpy@plt>
add    $0xffffffff,%ebp
jne    1250 <library_test+0xb0>
xor    %eax,%eax
call   10b0 <mytime@plt>
mov    %rax,%rbp
lea    0xda9(%rip),%rdi
call   1070 <print@plt>
sub    %r15,%rbp
mov    $0x4000000,%edi
mov    $0x64,%esi
mov    %rbp,%rdx
call   10c0 <calculate_result@plt>
xor    %eax,%eax
call   1040 <newline@plt>
xor    %eax,%eax
call   1050 <flush@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [17 x i8] c"Library: memset \00"
@.str.2 = [17 x i8] c"Library: memcpy \00"
define void @library_test() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = call i8* @malloc(i32 67108864)
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i8* @malloc(i32 67108864)
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = call i64 (...) @mytime()
store i64 %18, i64* %4
store i32 0, i32* %5
br label %19
19: ; preds = %26, %17
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 100
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i8*, i8** %1
%24 = load i32, i32* %5
%25 = call i32 @memset(i8* %23, i32 %24, i32 67108864)
br label %26
26: ; preds = %22
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %19
29: ; preds = %19
%30 = call i64 (...) @mytime()
store i64 %30, i64* %3
%31 = call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = load i64, i64* %3
%33 = load i64, i64* %4
%34 = sub i64 %32, %33
%35 = call i32 @calculate_result(i32 67108864, i32 100, i64 %34)
%36 = call i32 (...) @newline()
%37 = call i32 (...) @flush()
%38 = call i64 (...) @mytime()
store i64 %38, i64* %4
store i32 0, i32* %5
br label %39
39: ; preds = %46, %29
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 100
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i8*, i8** %2
%44 = load i8*, i8** %1
%45 = call i32 @memcpy(i8* %43, i8* %44, i32 67108864)
br label %46
46: ; preds = %42
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %39
49: ; preds = %39
%50 = call i64 (...) @mytime()
store i64 %50, i64* %3
%51 = call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%52 = load i64, i64* %3
%53 = load i64, i64* %4
%54 = sub i64 %52, %53
%55 = call i32 @calculate_result(i32 67108864, i32 100, i64 %54)
%56 = call i32 (...) @newline()
%57 = call i32 (...) @flush()
%58 = load i8*, i8** %1
%59 = call i32 @free(i8* %58)
%60 = load i8*, i8** %2
%61 = call i32 @free(i8* %60)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [17 x i8] c"Library: memset \00"
@.str.2 = [17 x i8] c"Library: memcpy \00"
define void @library_test() {
%1 = tail call dereferenceable_or_null(67108864) i8* @malloc(i32 67108864)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call dereferenceable_or_null(67108864) i8* @malloc(i32 67108864)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i64 (...) @mytime()
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 0, %10 ], [ %15, %12 ]
%14 = tail call i32 @memset(i8* %1, i32 %13, i32 67108864)
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, 100
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = tail call i64 (...) @mytime()
%19 = tail call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%20 = sub i64 %18, %11
%21 = tail call i32 @calculate_result(i32 67108864, i32 100, i64 %20)
%22 = tail call i32 (...) @newline()
%23 = tail call i32 (...) @flush()
%24 = tail call i64 (...) @mytime()
br label %25
25: ; preds = %17, %25
%26 = phi i32 [ 0, %17 ], [ %28, %25 ]
%27 = tail call i32 @memcpy(i8* %6, i8* %1, i32 67108864)
%28 = add nuw nsw i32 %26, 1
%29 = icmp eq i32 %28, 100
br i1 %29, label %30, label %25
30: ; preds = %25
%31 = tail call i64 (...) @mytime()
%32 = tail call i32 @print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%33 = sub i64 %31, %24
%34 = tail call i32 @calculate_result(i32 67108864, i32 100, i64 %33)
%35 = tail call i32 (...) @newline()
%36 = tail call i32 (...) @flush()
%37 = tail call i32 @free(i8* %1)
%38 = tail call i32 @free(i8* %6)
ret void
}