#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  unsigned int sum[4] = {0};
  unsigned int hdata, hlen = 0;
  FILE *fp = fopen("header.txt", "r");
  if (fp == NULL) {
    printf("error opening header.txt\n");
    return -1;
  }
  fscanf(fp, "%x", &hdata);
  printf("test %d\n", 0 + 0xff);
  while (!feof(fp)) {
    sum[hlen % 4] += hdata;
    sum[hlen % 4] = (sum[hlen % 4] >> 8) + (sum[hlen % 4] & 0xff);
    sum[hlen % 4] += (sum[hlen % 4] >> 8);
    printf("%02x: %02x sum(%x) ", (hlen + 1), hdata, sum[hlen % 4]);
    if (hlen == 44)
      break;
    hlen++;
    if (hlen % 10 == 0)
      printf("\n");
    fscanf(fp, "%x", &hdata);
  }
  printf("\nhlen = %d,sum[0-3] %02x-%02x-%02x-%02x \n", hlen, ~sum[0], ~sum[1],
         ~sum[2], ~sum[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x0,-0x28(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b2 <main+0x62>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1302 <main+0x1b2>
mov    -0x30(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
lea    0xe5d(%rip),%rdi
mov    $0xff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f7 <main+0xa7>
jmp    12ce <main+0x17e>
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
add    -0x20(%rbp,%rax,4),%ecx
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x20(%rbp,%rax,4),%ecx
shr    $0x8,%ecx
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x20(%rbp,%rax,4),%eax
and    $0xff,%eax
add    %eax,%ecx
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x20(%rbp,%rax,4),%ecx
shr    $0x8,%ecx
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
add    -0x20(%rbp,%rax,4),%ecx
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x28(%rbp),%esi
add    $0x1,%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x20(%rbp,%rax,4),%ecx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2c,-0x28(%rbp)
jne    1289 <main+0x139>
jmp    12ce <main+0x17e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    12b5 <main+0x165>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd67(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
jmp    11d9 <main+0x89>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
xor    $0xffffffff,%edx
mov    -0x1c(%rbp),%ecx
xor    $0xffffffff,%ecx
mov    -0x18(%rbp),%r8d
xor    $0xffffffff,%r8d
mov    -0x14(%rbp),%r9d
xor    $0xffffffff,%r9d
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xedd(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     129b <main+0x13b>
mov    %rax,%rbx
lea    0xe66(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
lea    0xe55(%rip),%rdi
xor    %r14d,%r14d
mov    $0xff,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
mov    $0xffffffff,%r9d
mov    $0xffffffff,%r8d
mov    $0xffffffff,%ecx
mov    $0xffffffff,%edx
mov    $0x0,%ebp
test   %eax,%eax
jne    12d3 <main+0x173>
mov    $0x1,%r14d
lea    0xe17(%rip),%r15
lea    0xc(%rsp),%r13
xor    %r12d,%r12d
jmp    1235 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xde8(%rip),%rsi
mov    %r13,%rdx
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
add    $0x1,%r14d
mov    %ebp,%r12d
test   %eax,%eax
jne    12b4 <main+0x154>
mov    0xc(%rsp),%edx
mov    %r12d,%eax
and    $0x3,%eax
mov    0x10(%rsp,%rax,4),%ecx
add    %edx,%ecx
movzbl %cl,%esi
shr    $0x8,%ecx
add    %ecx,%esi
mov    %esi,%ecx
shr    $0x8,%ecx
add    %esi,%ecx
mov    %ecx,0x10(%rsp,%rax,4)
lea    0x1(%r12),%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2c,%r12d
je     12af <main+0x14f>
mov    %r14d,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
add    %eax,%eax
add    $0xffffffff,%eax
cmp    %r12d,%eax
jne    1210 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1210 <main+0xb0>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
jmp    12e3 <main+0x183>
mov    $0x2c,%ebp
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0x18(%rsp),%r8d
mov    0x1c(%rsp),%r9d
not    %edx
not    %ecx
not    %r8d
not    %r9d
xor    %r14d,%r14d
lea    0xd48(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"header.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"error opening header.txt\0A\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [9 x i8] c"test %d\0A\00"
@.str.5 = [20 x i8] c"%02x: %02x sum(%x) \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [42 x i8] c"\0Ahlen = %d,sum[0-3] %02x-%02x-%02x-%02x \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
%6 = bitcast [4 x i32]* %2 to i8*
store i32 0, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %96
12: ; preds = %0
%13 = load i32*, i32** %5
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 255)
br label %16
16: ; preds = %78, %12
%17 = load i32*, i32** %5
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %81
21: ; preds = %16
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = urem i32 %23, 4
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add i32 %27, %22
store i32 %28, i32* %26
%29 = load i32, i32* %4
%30 = urem i32 %29, 4
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = lshr i32 %33, 8
%35 = load i32, i32* %4
%36 = urem i32 %35, 4
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = and i32 %39, 255
%41 = add i32 %34, %40
%42 = load i32, i32* %4
%43 = urem i32 %42, 4
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %44
store i32 %41, i32* %45
%46 = load i32, i32* %4
%47 = urem i32 %46, 4
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = lshr i32 %50, 8
%52 = load i32, i32* %4
%53 = urem i32 %52, 4
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = add i32 %56, %51
store i32 %57, i32* %55
%58 = load i32, i32* %4
%59 = add i32 %58, 1
%60 = load i32, i32* %3
%61 = load i32, i32* %4
%62 = urem i32 %61, 4
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %59, i32 %60, i32 %65)
%67 = load i32, i32* %4
%68 = icmp eq i32 %67, 44
br i1 %68, label %69, label %70
69: ; preds = %21
br label %81
70: ; preds = %21
%71 = load i32, i32* %4
%72 = add i32 %71, 1
store i32 %72, i32* %4
%73 = load i32, i32* %4
%74 = urem i32 %73, 10
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %70
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %78
78: ; preds = %76, %70
%79 = load i32*, i32** %5
%80 = call i32 @fscanf(i32* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %16
81: ; preds = %69, %16
%82 = load i32, i32* %4
%83 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%84 = load i32, i32* %83
%85 = xor i32 %84, -1
%86 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%87 = load i32, i32* %86
%88 = xor i32 %87, -1
%89 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%90 = load i32, i32* %89
%91 = xor i32 %90, -1
%92 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%93 = load i32, i32* %92
%94 = xor i32 %93, -1
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %82, i32 %85, i32 %88, i32 %91, i32 %94)
store i32 0, i32* %1
br label %96
96: ; preds = %81, %10
%97 = load i32, i32* %1
ret i32 %97
}

LLVM IR (-O2):
@.str = [11 x i8] c"header.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [9 x i8] c"test %d\0A\00"
@.str.5 = [20 x i8] c"%02x: %02x sum(%x) \00"
@.str.7 = [42 x i8] c"\0Ahlen = %d,sum[0-3] %02x-%02x-%02x-%02x \0A\00"
@str = [25 x i8] c"error opening header.txt\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = alloca i32
%3 = bitcast [4 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %60
9: ; preds = %0
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 255)
%12 = call i32 @feof(i32* %5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %53
14: ; preds = %9, %35
%15 = phi i32 [ %27, %35 ], [ 0, %9 ]
%16 = load i32, i32* %2
%17 = and i32 %15, 3
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = add i32 %20, %16
%22 = lshr i32 %21, 8
%23 = and i32 %21, 255
%24 = add nuw nsw i32 %22, %23
%25 = lshr i32 %24, 8
%26 = add nuw nsw i32 %25, %24
store i32 %26, i32* %19
%27 = add nuw nsw i32 %15, 1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %16, i32 %26)
%29 = icmp eq i32 %15, 44
br i1 %29, label %39, label %30
30: ; preds = %14
%31 = urem i32 %27, 10
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @putchar(i32 10)
br label %35
35: ; preds = %33, %30
%36 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%37 = call i32 @feof(i32* %5)
%38 = icmp eq i32 %37, 0
br i1 %38, label %14, label %39
39: ; preds = %14, %35
%40 = phi i32 [ %27, %35 ], [ 44, %14 ]
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%46 = load i32, i32* %45
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
%48 = load i32, i32* %47
%49 = xor i32 %42, -1
%50 = xor i32 %44, -1
%51 = xor i32 %46, -1
%52 = xor i32 %48, -1
br label %53
53: ; preds = %39, %9
%54 = phi i32 [ -1, %9 ], [ %52, %39 ]
%55 = phi i32 [ -1, %9 ], [ %51, %39 ]
%56 = phi i32 [ -1, %9 ], [ %50, %39 ]
%57 = phi i32 [ -1, %9 ], [ %49, %39 ]
%58 = phi i32 [ 0, %9 ], [ %40, %39 ]
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %58, i32 %57, i32 %56, i32 %55, i32 %54)
br label %60
60: ; preds = %53, %7
%61 = phi i32 [ -1, %7 ], [ 0, %53 ]
ret i32 %61
}