#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 uint8_t;

/* Variables and functions */
int crc8(int *, int);
int /*<<< orphan*/ free(int *);
int get_value(long);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  uint8_t *buf = malloc(100000000);
  long i;
  for (i = 0; i < 100000000; i++)
    buf[i] = get_value(i);
  uint8_t crc = crc8(buf, 100000000);
  free(buf);
  printf("0x%02x\n", crc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x5f5e100,-0x18(%rbp)
05
jge    11aa <main+0x5a>
mov    -0x18(%rbp),%rdi
call   1060 <get_value@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <main+0x25>
mov    -0x10(%rbp),%rdi
mov    $0x5f5e100,%esi
call   1070 <crc8@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x5f5e100,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <get_value@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x5f5e100,%rbx
jne    1170 <main+0x20>
mov    %r14,%rdi
mov    $0x5f5e100,%esi
call   1070 <crc8@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"0x%02x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @malloc(i32 100000000)
store i32* %5, i32** %2
store i64 0, i64* %3
br label %6
6: ; preds = %15, %0
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 100000000
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load i64, i64* %3
%11 = call i32 @get_value(i64 %10)
%12 = load i32*, i32** %2
%13 = load i64, i64* %3
%14 = getelementptr inbounds i32, i32* %12, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %9
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 1
store i64 %17, i64* %3
br label %6
18: ; preds = %6
%19 = load i32*, i32** %2
%20 = call i32 @crc8(i32* %19, i32 100000000)
store i32 %20, i32* %4
%21 = load i32*, i32** %2
%22 = call i32 @free(i32* %21)
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"0x%02x\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 100000000)
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %6, %2 ]
%4 = tail call i32 @get_value(i64 %3)
%5 = getelementptr inbounds i32, i32* %1, i64 %3
store i32 %4, i32* %5
%6 = add nuw nsw i64 %3, 1
%7 = icmp eq i64 %6, 100000000
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = tail call i32 @crc8(i32* %1, i32 100000000)
%10 = tail call i32 @free(i32* %1)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
ret i32 0
}