#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*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  unsigned char bytes[2];
  int sum = 0;
  int count = 0;
  FILE *fp = fopen("1988730searlymelt.int.304.448.c", "rb");
  while (fread(bytes, 2, 1, fp) != 0) {
    int piece = bytes[0] | (bytes[1] << 8);
    sum += piece;
    printf("The piece is %d\n", piece);
    count = count + 1;
  }
  printf("The sum is %d\n", sum);
  printf("the total count is %d\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x6(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     11bb <main+0x8b>
movzbl -0x6(%rbp),%eax
movzbl -0x5(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <main+0x34>
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
lea    0xed6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11ae <main+0x7e>
xor    %ebx,%ebx
lea    0xeac(%rip),%r15
lea    0xe(%rsp),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
movzwl 0xe(%rsp),%esi
add    %esi,%ebx
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1180 <main+0x50>
jmp    11b2 <main+0x82>
xor    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe7b(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"1988730searlymelt.int.304.448.c\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [17 x i8] c"The piece is %d\0A\00"
@.str.3 = [15 x i8] c"The sum is %d\0A\00"
@.str.4 = [23 x i8] c"the total count is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
br label %8
8: ; preds = %13, %0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%10 = load i32*, i32** %5
%11 = call i64 @fread(i8* %9, i32 2, i32 1, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = shl i32 %19, 8
%21 = or i32 %16, %20
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %22
store i32 %24, i32* %3
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %8
29: ; preds = %8
%30 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"1988730searlymelt.int.304.448.c\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [17 x i8] c"The piece is %d\0A\00"
@.str.3 = [15 x i8] c"The sum is %d\0A\00"
@.str.4 = [23 x i8] c"the total count is %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = call i64 @fread(i8* %2, i32 2, i32 1, i32* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 0, %6 ], [ %17, %8 ]
%10 = phi i32 [ 0, %6 ], [ %19, %8 ]
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 %14, 8
%16 = or i32 %15, %12
%17 = add nuw nsw i32 %16, %9
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%19 = add nuw nsw i32 %10, 1
%20 = call i64 @fread(i8* %2, i32 2, i32 1, i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %8, %0
%23 = phi i32 [ 0, %0 ], [ %19, %8 ]
%24 = phi i32 [ 0, %0 ], [ %17, %8 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %23)
ret i32 0
}