#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*/ printf(char *, unsigned char);
int edid_checksum(unsigned char *edid) {
  unsigned char csum = 0;
  int i, ok = 0;
  for (i = 0; i < 128; i++)
    csum += edid[i];
  printf("checksum = 0x%02x\n", csum);
  if (csum == 0x00)
    ok = 1;
  return ok;
}


x86 assembly (clang, -O0):
<edid_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x80,-0x10(%rbp)
jge    115e <edid_checksum+0x4e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
movzbl -0x9(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <edid_checksum+0x1e>
lea    0xe9b(%rip),%rdi
movzbl -0x9(%rbp),%esi
call   1030 <printf@plt>
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    1182 <edid_checksum+0x72>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edid_checksum>:
push   %rbx
movdqu (%rdi),%xmm0
movdqu 0x10(%rdi),%xmm1
movdqu 0x20(%rdi),%xmm2
paddb  %xmm0,%xmm2
movdqu 0x30(%rdi),%xmm0
paddb  %xmm1,%xmm0
movdqu 0x40(%rdi),%xmm1
movdqu 0x50(%rdi),%xmm3
movdqu 0x60(%rdi),%xmm4
paddb  %xmm1,%xmm4
paddb  %xmm2,%xmm4
movdqu 0x70(%rdi),%xmm1
paddb  %xmm3,%xmm1
paddb  %xmm0,%xmm1
paddb  %xmm4,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddb  %xmm1,%xmm0
pxor   %xmm1,%xmm1
psadbw %xmm0,%xmm1
movd   %xmm1,%eax
movzbl %al,%ebx
lea    0xe8d(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
test   %bl,%bl
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"checksum = 0x%02x\0A\00"
define i32 @edid_checksum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i8 0, i8* %3
store i32 0, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 128
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = load i8, i8* %3
%17 = zext i8 %16 to i32
%18 = add nsw i32 %17, %15
%19 = trunc i32 %18 to i8
store i8 %19, i8* %3
br label %20
20: ; preds = %9
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %6
23: ; preds = %6
%24 = load i8, i8* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = load i8, i8* %3
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %5
br label %30
30: ; preds = %29, %23
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"checksum = 0x%02x\0A\00"
define i32 @edid_checksum(i8* nocapture %0) {
%2 = bitcast i8* %0 to <16 x i8>*
%3 = load <16 x i8>, <16 x i8>* %2
%4 = getelementptr inbounds i8, i8* %0, i64 16
%5 = bitcast i8* %4 to <16 x i8>*
%6 = load <16 x i8>, <16 x i8>* %5
%7 = getelementptr inbounds i8, i8* %0, i64 32
%8 = bitcast i8* %7 to <16 x i8>*
%9 = load <16 x i8>, <16 x i8>* %8
%10 = getelementptr inbounds i8, i8* %0, i64 48
%11 = bitcast i8* %10 to <16 x i8>*
%12 = load <16 x i8>, <16 x i8>* %11
%13 = add <16 x i8> %9, %3
%14 = add <16 x i8> %12, %6
%15 = getelementptr inbounds i8, i8* %0, i64 64
%16 = bitcast i8* %15 to <16 x i8>*
%17 = load <16 x i8>, <16 x i8>* %16
%18 = getelementptr inbounds i8, i8* %0, i64 80
%19 = bitcast i8* %18 to <16 x i8>*
%20 = load <16 x i8>, <16 x i8>* %19
%21 = add <16 x i8> %17, %13
%22 = add <16 x i8> %20, %14
%23 = getelementptr inbounds i8, i8* %0, i64 96
%24 = bitcast i8* %23 to <16 x i8>*
%25 = load <16 x i8>, <16 x i8>* %24
%26 = getelementptr inbounds i8, i8* %0, i64 112
%27 = bitcast i8* %26 to <16 x i8>*
%28 = load <16 x i8>, <16 x i8>* %27
%29 = add <16 x i8> %25, %21
%30 = add <16 x i8> %28, %22
%31 = add <16 x i8> %30, %29
%32 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %31)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
%34 = icmp eq i8 %32, 0
%35 = zext i1 %34 to i32
ret i32 %35
}