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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int read(int, int *, int);
int getbootfilecsum(const char *file) {
  uint32_t b, csum;
  int fd;
  fd = open(file, O_RDONLY);
  assert(fd != -1);
  lseek(fd, 64, SEEK_SET);
  csum = 0;
  while (read(fd, &b, 4) == 4) {
    csum += b;
  }
  close(fd);
  return csum;
}


x86 assembly (clang, -O0):
<getbootfilecsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1030 <lseek@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11c7 <getbootfilecsum+0x77>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    119f <getbootfilecsum+0x4f>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbootfilecsum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x40,%esi
call   1030 <lseek@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
jne    11c8 <getbootfilecsum+0x78>
xor    %ebp,%ebp
lea    0xc(%rsp),%r14
nopw   0x0(%rax,%rax,1)
add    0xc(%rsp),%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     11b0 <getbootfilecsum+0x60>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i32 @getbootfilecsum(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, -1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 64, i32 %14)
store i32 0, i32* %4
br label %16
16: ; preds = %20, %1
%17 = load i32, i32* %5
%18 = call i32 @read(i32 %17, i32* %3, i32 4)
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %21
store i32 %23, i32* %4
br label %16
24: ; preds = %16
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i32 @getbootfilecsum(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp ne i32 %5, -1
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %5, i32 64, i32 %9)
%11 = call i32 @read(i32 %5, i32* %2, i32 4)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %1, %13
%14 = phi i32 [ %16, %13 ], [ 0, %1 ]
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %14
%17 = call i32 @read(i32 %5, i32* %2, i32 4)
%18 = icmp eq i32 %17, 4
br i1 %18, label %13, label %19
19: ; preds = %13, %1
%20 = phi i32 [ 0, %1 ], [ %16, %13 ]
%21 = tail call i32 @close(i32 %5)
ret i32 %20
}