#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 scalar_t__ uint8_t;
typedef int /*<<< orphan*/ uint16_t;
struct stat {
  scalar_t__ st_size;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ read(int, scalar_t__ *, int);
uint16_t method2(int f) {
  struct stat buf;
  fstat(f, &buf);
  off_t size = buf.st_size;
  uint16_t chksum16 = 0;
  uint8_t data = 0;
  for (off_t i = 0; i < size; ++i) {
    read(f, &data, 0x01);
    chksum16 += data;
  }
  return chksum16;
}


x86 assembly (clang, -O0):
<method2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <fstat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1194 <method2+0x74>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    -0x28(%rbp),%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1156 <method2+0x36>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<method2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
lea    0x10(%rsp),%rsi
call   1040 <fstat@plt>
mov    0x10(%rsp),%rbx
movq   $0x0,0x8(%rsp)
xor    %ebp,%ebp
test   %rbx,%rbx
jle    117a <method2+0x5a>
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
add    0x8(%rsp),%ebp
add    $0xffffffffffffffff,%rbx
jne    1160 <method2+0x40>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @method2(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @fstat(i32 %8, %struct.stat* %3)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%11 = load i64, i64* %10
store i64 %11, i64* %4
store i32 0, i32* %5
store i64 0, i64* %6
store i64 0, i64* %7
br label %12
12: ; preds = %24, %1
%13 = load i64, i64* %7
%14 = load i64, i64* %4
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i32, i32* %2
%18 = call i32 @read(i32 %17, i64* %6, i32 1)
%19 = load i64, i64* %6
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
br label %24
24: ; preds = %16
%25 = load i64, i64* %7
%26 = add nsw i64 %25, 1
store i64 %26, i64* %7
br label %12
27: ; preds = %12
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @method2(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca i64
%4 = bitcast %struct.stat* %2 to i8*
%5 = call i32 @fstat(i32 %0, %struct.stat* %2)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%9 = icmp sgt i64 %7, 0
br i1 %9, label %12, label %10
10: ; preds = %12, %1
%11 = phi i32 [ 0, %1 ], [ %18, %12 ]
ret i32 %11
12: ; preds = %1, %12
%13 = phi i64 [ %19, %12 ], [ 0, %1 ]
%14 = phi i32 [ %18, %12 ], [ 0, %1 ]
%15 = call i32 @read(i32 %0, i64* %3, i32 1)
%16 = load i64, i64* %3
%17 = trunc i64 %16 to i32
%18 = add i32 %14, %17
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %10, label %12
}