#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 */
char fgetc(int /*<<< orphan*/ *);
unsigned char calc_checksum(FILE *input) {
  char c;
  unsigned char checksum = 0;
  unsigned int i = 0;
  while (i < 0x0134) {
    c = fgetc(input);
    ++i;
  }
  while (i < 0x014D) {
    c = fgetc(input);
    checksum = checksum - c - 1;
    ++i;
  }
  return checksum;
}


x86 assembly (clang, -O0):
<calc_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xa(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x134,-0x10(%rbp)
jae    114e <calc_checksum+0x3e>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1127 <calc_checksum+0x17>
jmp    1153 <calc_checksum+0x43>
cmpl   $0x14d,-0x10(%rbp)
jae    118a <calc_checksum+0x7a>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%eax
movsbl -0x9(%rbp),%ecx
sub    %ecx,%eax
sub    $0x1,%eax
mov    %al,-0xa(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1153 <calc_checksum+0x43>
movzbl -0xa(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_checksum>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x134,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
add    $0xffffffff,%ebp
jne    1120 <calc_checksum+0x10>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
not    %bpl
add    %r14b,%bpl
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%r14d
not    %r14b
add    %bpl,%r14b
mov    %rbx,%rdi
call   1030 <fgetc@plt>
not    %al
add    %r14b,%al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @calc_checksum(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %2
store i8 0, i8* %4
store i32 0, i32* %5
br label %6
6: ; preds = %9, %1
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 308
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32*, i32** %2
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %3
%12 = load i32, i32* %5
%13 = add i32 %12, 1
store i32 %13, i32* %5
br label %6
14: ; preds = %6
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %5
%17 = icmp ult i32 %16, 333
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32*, i32** %2
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %3
%21 = load i8, i8* %4
%22 = zext i8 %21 to i32
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %22, %24
%26 = sub nsw i32 %25, 1
%27 = trunc i32 %26 to i8
store i8 %27, i8* %4
%28 = load i32, i32* %5
%29 = add i32 %28, 1
store i32 %29, i32* %5
br label %15
30: ; preds = %15
%31 = load i8, i8* %4
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @calc_checksum(i32* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %5, %2 ]
%4 = tail call signext i8 @fgetc(i32* %0)
%5 = add nuw nsw i32 %3, 1
%6 = icmp eq i32 %5, 308
br i1 %6, label %7, label %2
7: ; preds = %2
%8 = tail call signext i8 @fgetc(i32* %0)
%9 = xor i8 %8, -1
%10 = tail call signext i8 @fgetc(i32* %0)
%11 = xor i8 %10, -1
%12 = add i8 %9, %11
%13 = tail call signext i8 @fgetc(i32* %0)
%14 = xor i8 %13, -1
%15 = add i8 %12, %14
%16 = tail call signext i8 @fgetc(i32* %0)
%17 = xor i8 %16, -1
%18 = add i8 %15, %17
%19 = tail call signext i8 @fgetc(i32* %0)
%20 = xor i8 %19, -1
%21 = add i8 %18, %20
%22 = tail call signext i8 @fgetc(i32* %0)
%23 = xor i8 %22, -1
%24 = add i8 %21, %23
%25 = tail call signext i8 @fgetc(i32* %0)
%26 = xor i8 %25, -1
%27 = add i8 %24, %26
%28 = tail call signext i8 @fgetc(i32* %0)
%29 = xor i8 %28, -1
%30 = add i8 %27, %29
%31 = tail call signext i8 @fgetc(i32* %0)
%32 = xor i8 %31, -1
%33 = add i8 %30, %32
%34 = tail call signext i8 @fgetc(i32* %0)
%35 = xor i8 %34, -1
%36 = add i8 %33, %35
%37 = tail call signext i8 @fgetc(i32* %0)
%38 = xor i8 %37, -1
%39 = add i8 %36, %38
%40 = tail call signext i8 @fgetc(i32* %0)
%41 = xor i8 %40, -1
%42 = add i8 %39, %41
%43 = tail call signext i8 @fgetc(i32* %0)
%44 = xor i8 %43, -1
%45 = add i8 %42, %44
%46 = tail call signext i8 @fgetc(i32* %0)
%47 = xor i8 %46, -1
%48 = add i8 %45, %47
%49 = tail call signext i8 @fgetc(i32* %0)
%50 = xor i8 %49, -1
%51 = add i8 %48, %50
%52 = tail call signext i8 @fgetc(i32* %0)
%53 = xor i8 %52, -1
%54 = add i8 %51, %53
%55 = tail call signext i8 @fgetc(i32* %0)
%56 = xor i8 %55, -1
%57 = add i8 %54, %56
%58 = tail call signext i8 @fgetc(i32* %0)
%59 = xor i8 %58, -1
%60 = add i8 %57, %59
%61 = tail call signext i8 @fgetc(i32* %0)
%62 = xor i8 %61, -1
%63 = add i8 %60, %62
%64 = tail call signext i8 @fgetc(i32* %0)
%65 = xor i8 %64, -1
%66 = add i8 %63, %65
%67 = tail call signext i8 @fgetc(i32* %0)
%68 = xor i8 %67, -1
%69 = add i8 %66, %68
%70 = tail call signext i8 @fgetc(i32* %0)
%71 = xor i8 %70, -1
%72 = add i8 %69, %71
%73 = tail call signext i8 @fgetc(i32* %0)
%74 = xor i8 %73, -1
%75 = add i8 %72, %74
%76 = tail call signext i8 @fgetc(i32* %0)
%77 = xor i8 %76, -1
%78 = add i8 %75, %77
%79 = tail call signext i8 @fgetc(i32* %0)
%80 = xor i8 %79, -1
%81 = add i8 %78, %80
ret i8 %81
}