#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*/ 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, int /*<<< orphan*/ *, int);
uint16_t method1(int f) {
  struct stat buf;
  fstat(f, &buf);
  off_t size = buf.st_size;
  uint16_t chksum16 = 0;
  uint16_t data;
  for (off_t i = 0; i < size; i += 2) {
    read(f, &data, 0x02);
    chksum16 ^= data;
  }
  return chksum16;
}


x86 assembly (clang, -O0):
<method1>:
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)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1187 <method1+0x67>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1030 <read@plt>
mov    -0x20(%rbp),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    114e <method1+0x2e>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<method1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r15d
lea    0x8(%rsp),%rsi
call   1040 <fstat@plt>
mov    0x8(%rsp),%r12
test   %r12,%r12
jle    116f <method1+0x4f>
xor    %ebx,%ebx
lea    0x4(%rsp),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <read@plt>
xor    0x4(%rsp),%ebp
add    $0x2,%rbx
cmp    %r12,%rbx
jl     1150 <method1+0x30>
jmp    1171 <method1+0x51>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @method1(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%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* %7
br label %12
12: ; preds = %22, %1
%13 = load i64, i64* %7
%14 = load i64, i64* %4
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %2
%18 = call i32 @read(i32 %17, i32* %6, i32 2)
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = xor i32 %20, %19
store i32 %21, i32* %5
br label %22
22: ; preds = %16
%23 = load i64, i64* %7
%24 = add nsw i64 %23, 2
store i64 %24, i64* %7
br label %12
25: ; preds = %12
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @method1(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca i32
%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 i32* %3 to i8*
%9 = icmp sgt i64 %7, 0
br i1 %9, label %12, label %10
10: ; preds = %12, %1
%11 = phi i32 [ 0, %1 ], [ %17, %12 ]
ret i32 %11
12: ; preds = %1, %12
%13 = phi i64 [ %18, %12 ], [ 0, %1 ]
%14 = phi i32 [ %17, %12 ], [ 0, %1 ]
%15 = call i32 @read(i32 %0, i32* %3, i32 2)
%16 = load i32, i32* %3
%17 = xor i32 %16, %14
%18 = add nuw nsw i64 %13, 2
%19 = icmp slt i64 %18, %7
br i1 %19, label %12, label %10
}