#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*/ XSUM_benchMem(void const *const, size_t);
int /*<<< orphan*/ XSUM_log(char *);
int /*<<< orphan*/ XSUM_logVerbose(int, char *, ...);
void *calloc(size_t, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(void *const);
int XSUM_benchInternal(size_t keySize) {
  void *const buffer = calloc(keySize + 16 + 3, 1);
  if (buffer == NULL) {
    XSUM_log("\nError: Out of memory.\n");
    exit(12);
  }
  {
    const void *const alignedBuffer =
        ((char *)buffer + 15) - (((size_t)((char *)buffer + 15)) & 0xF);
    XSUM_logVerbose(1, "Sample of ");
    if (keySize > 10 * (1 << 10)) {
      XSUM_logVerbose(1, "%u KB", (unsigned)(keySize >> 10));
    } else {
      XSUM_logVerbose(1, "%u bytes", (unsigned)keySize);
    }
    XSUM_logVerbose(1, "...        \n");
    XSUM_benchMem(alignedBuffer, keySize);
    free(buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<XSUM_benchInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
add    $0x3,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <XSUM_benchInternal+0x47>
lea    0xe68(%rip),%rdi
call   1070 <XSUM_log@plt>
mov    $0xc,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0xf,%rax
mov    -0x10(%rbp),%rdx
add    $0xf,%rdx
and    $0xf,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1040 <XSUM_logVerbose@plt>
cmpq   $0x2800,-0x8(%rbp)
jbe    120a <XSUM_benchInternal+0xaa>
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1040 <XSUM_logVerbose@plt>
jmp    1223 <XSUM_benchInternal+0xc3>
mov    -0x8(%rbp),%rax
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1040 <XSUM_logVerbose@plt>
mov    $0x1,%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <XSUM_logVerbose@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <XSUM_benchMem@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XSUM_benchInternal>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
add    $0x13,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11fa <XSUM_benchInternal+0x9a>
mov    %rax,%r14
mov    %rax,%rbx
add    $0xf,%rbx
lea    0xe8c(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <XSUM_logVerbose@plt>
mov    %r15,%rdx
shr    $0xa,%rdx
cmp    $0x2801,%r15
lea    0xe76(%rip),%rax
lea    0xe75(%rip),%rsi
cmovae %rax,%rsi
cmovb  %r15d,%edx
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <XSUM_logVerbose@plt>
and    $0xfffffffffffffff0,%rbx
lea    0xe5f(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <XSUM_logVerbose@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <XSUM_benchMem@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdff(%rip),%rdi
call   1070 <XSUM_log@plt>
mov    $0xc,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"\0AError: Out of memory.\0A\00"
@.str.1 = [11 x i8] c"Sample of \00"
@.str.2 = [6 x i8] c"%u KB\00"
@.str.3 = [9 x i8] c"%u bytes\00"
@.str.4 = [13 x i8] c"... \0A\00"
define i32 @XSUM_benchInternal(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = add i64 %5, 16
%7 = add i64 %6, 3
%8 = call i8* @calloc(i64 %7, i32 1)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @XSUM_log(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 12)
unreachable
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 15
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 15
%19 = ptrtoint i8* %18 to i64
%20 = and i64 %19, 15
%21 = sub i64 0, %20
%22 = getelementptr inbounds i8, i8* %16, i64 %21
store i8* %22, i8** %4
%23 = call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = load i64, i64* %2
%25 = icmp ugt i64 %24, 10240
br i1 %25, label %26, label %31
26: ; preds = %14
%27 = load i64, i64* %2
%28 = lshr i64 %27, 10
%29 = trunc i64 %28 to i32
%30 = call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %35
31: ; preds = %14
%32 = load i64, i64* %2
%33 = trunc i64 %32 to i32
%34 = call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %31, %26
%36 = call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%37 = load i8*, i8** %4
%38 = load i64, i64* %2
%39 = call i32 @XSUM_benchMem(i8* %37, i64 %38)
%40 = load i8*, i8** %3
%41 = call i32 @free(i8* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"\0AError: Out of memory.\0A\00"
@.str.1 = [11 x i8] c"Sample of \00"
@.str.2 = [6 x i8] c"%u KB\00"
@.str.3 = [9 x i8] c"%u bytes\00"
@.str.4 = [13 x i8] c"... \0A\00"
define i32 @XSUM_benchInternal(i64 %0) {
%2 = add i64 %0, 19
%3 = tail call i8* @calloc(i64 %2, i32 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @XSUM_log(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 12)
unreachable
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %3, i64 15
%10 = tail call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ugt i64 %0, 10240
%12 = lshr i64 %0, 10
%13 = select i1 %11, i64 %12, i64 %0
%14 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
%15 = trunc i64 %13 to i32
%16 = tail call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* %14, i32 %15)
%17 = ptrtoint i8* %9 to i64
%18 = and i64 %17, 15
%19 = sub nsw i64 0, %18
%20 = getelementptr inbounds i8, i8* %9, i64 %19
%21 = tail call i32 (i32, i8*, ...) @XSUM_logVerbose(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 @XSUM_benchMem(i8* %20, i64 %0)
%23 = tail call i32 @free(i8* %3)
ret i32 0
}