#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;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ prnum(int);
int read(int /*<<< orphan*/, int *, int);
void c_sum() {
  uint8_t *p;
  uint32_t hval = 2166136261U;
  uint32_t size = 0;
  uint8_t buf[512];
  for (;;) {
    int len = read(0, buf, sizeof buf);
    if (len <= 0)
      break;
    size += len;
    for (p = buf; p < buf + len; ++p) {
      hval ^= *p;
      hval *= 16777619;
    }
  }
  prnum(hval);
  prnum(size);
}


x86 assembly (clang, -O0):
<c_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x811c9dc5,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x810(%rbp),%rsi
xor    %edi,%edi
mov    $0x800,%edx
call   1030 <read@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jg     1164 <c_sum+0x44>
jmp    11c9 <c_sum+0xa9>
mov    -0x814(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
lea    -0x810(%rbp),%rcx
movslq -0x814(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11c4 <c_sum+0xa4>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0x1000193,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    117b <c_sum+0x5b>
jmp    1139 <c_sum+0x19>
mov    -0xc(%rbp),%edi
call   1040 <prnum@plt>
mov    -0x10(%rbp),%edi
call   1040 <prnum@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_sum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
xor    %ebx,%ebx
mov    %rsp,%r14
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x800,%edx
call   1030 <read@plt>
mov    $0x811c9dc5,%ebp
test   %eax,%eax
jle    1184 <c_sum+0x64>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    %eax,%ebx
mov    %eax,%eax
lea    (%rsp,%rax,4),%rax
mov    %r14,%rcx
nopl   0x0(%rax,%rax,1)
xor    (%rcx),%ebp
imul   $0x1000193,%ebp,%ebp
add    $0x4,%rcx
cmp    %rax,%rcx
jb     1160 <c_sum+0x40>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x800,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     1150 <c_sum+0x30>
mov    %ebp,%edi
call   1040 <prnum@plt>
mov    %ebx,%edi
call   1040 <prnum@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @c_sum() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i32]
%5 = alloca i32
store i32 -2128831035, i32* %2
store i32 0, i32* %3
br label %6
6: ; preds = %34, %0
%7 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 0
%8 = call i32 @read(i32 0, i32* %7, i32 2048)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
br label %35
12: ; preds = %6
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = add nsw i32 %14, %13
store i32 %15, i32* %3
%16 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 0
store i32* %16, i32** %1
br label %17
17: ; preds = %31, %12
%18 = load i32*, i32** %1
%19 = getelementptr inbounds [512 x i32], [512 x i32]* %4, i64 0, i64 0
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = icmp ult i32* %18, %22
br i1 %23, label %24, label %34
24: ; preds = %17
%25 = load i32*, i32** %1
%26 = load i32, i32* %25
%27 = load i32, i32* %2
%28 = xor i32 %27, %26
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = mul nsw i32 %29, 16777619
store i32 %30, i32* %2
br label %31
31: ; preds = %24
%32 = load i32*, i32** %1
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %1
br label %17
34: ; preds = %17
br label %6
35: ; preds = %11
%36 = load i32, i32* %2
%37 = call i32 @prnum(i32 %36)
%38 = load i32, i32* %3
%39 = call i32 @prnum(i32 %38)
ret void
}

LLVM IR (-O2):
define void @c_sum() {
%1 = alloca [512 x i32]
%2 = bitcast [512 x i32]* %1 to i8*
%3 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%4 = call i32 @read(i32 0, i32* %3, i32 2048)
%5 = icmp slt i32 %4, 1
br i1 %5, label %24, label %9
6: ; preds = %16
%7 = call i32 @read(i32 0, i32* %3, i32 2048)
%8 = icmp slt i32 %7, 1
br i1 %8, label %24, label %9
9: ; preds = %0, %6
%10 = phi i32 [ %7, %6 ], [ %4, %0 ]
%11 = phi i32 [ %13, %6 ], [ 0, %0 ]
%12 = phi i32 [ %21, %6 ], [ -2128831035, %0 ]
%13 = add nsw i32 %10, %11
%14 = zext i32 %10 to i64
%15 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 %14
br label %16
16: ; preds = %9, %16
%17 = phi i32* [ %22, %16 ], [ %3, %9 ]
%18 = phi i32 [ %21, %16 ], [ %12, %9 ]
%19 = load i32, i32* %17
%20 = xor i32 %19, %18
%21 = mul nsw i32 %20, 16777619
%22 = getelementptr inbounds i32, i32* %17, i64 1
%23 = icmp ult i32* %22, %15
br i1 %23, label %16, label %6
24: ; preds = %6, %0
%25 = phi i32 [ -2128831035, %0 ], [ %21, %6 ]
%26 = phi i32 [ 0, %0 ], [ %13, %6 ]
%27 = call i32 @prnum(i32 %25)
%28 = call i32 @prnum(i32 %26)
ret void
}