#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 EINVAL;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  uint32_t t = 0, sum = 0x55aa55aa;
  int fd;
  if ((argc != 2) || ((fd = open(argv[1], O_RDWR)) == -1)) {
    fprintf(stderr, "Usage: %s input_file\n", *argv);
    return -EINVAL;
  }
  lseek(fd, -4, SEEK_END);
  write(fd, &t, 4);
  lseek(fd, 0, SEEK_SET);
  while (read(fd, &t, 4) > 0)
    sum -= t;
  lseek(fd, -4, SEEK_END);
  write(fd, &sum, 4);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x55aa55aa,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11df <main+0x7f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
mov    0x2deb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <main+0x11a>
mov    -0x1c(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    1244 <main+0xe4>
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1219 <main+0xb9>
mov    -0x1c(%rbp),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
mov    %rsi,%rbp
movl   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jne    1245 <main+0xe5>
mov    0x8(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1245 <main+0xe5>
mov    %eax,%ebx
mov    0x2e3c(%rip),%r15
mov    (%r15),%edx
mov    %eax,%edi
mov    $0xfffffffc,%esi
call   1040 <lseek@plt>
lea    0x8(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    $0x55aa55aa,%ebp
test   %rax,%rax
jle    1218 <main+0xb8>
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
sub    0x8(%rsp),%ebp
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     1200 <main+0xa0>
mov    %ebp,0xc(%rsp)
mov    (%r15),%edx
mov    %ebx,%edi
mov    $0xfffffffc,%esi
call   1040 <lseek@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    126b <main+0x10b>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xda7(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d5b(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s input_file\0A\00"
@EINVAL = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1437226410, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %11, %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
store i32 %24, i32* %3
br label %50
25: ; preds = %11
%26 = load i32, i32* %8
%27 = load i32, i32* @SEEK_END
%28 = call i32 @lseek(i32 %26, i32 -4, i32 %27)
%29 = load i32, i32* %8
%30 = call i32 @write(i32 %29, i32* %6, i32 4)
%31 = load i32, i32* %8
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @lseek(i32 %31, i32 0, i32 %32)
br label %34
34: ; preds = %38, %25
%35 = load i32, i32* %8
%36 = call i64 @read(i32 %35, i32* %6, i32 4)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, %39
store i32 %41, i32* %7
br label %34
42: ; preds = %34
%43 = load i32, i32* %8
%44 = load i32, i32* @SEEK_END
%45 = call i32 @lseek(i32 %43, i32 -4, i32 %44)
%46 = load i32, i32* %8
%47 = call i32 @write(i32 %46, i32* %7, i32 4)
%48 = load i32, i32* %8
%49 = call i32 @close(i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %42, %18
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Usage: %s input_file\0A\00"
@EINVAL = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %8, %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EINVAL
%19 = sub nsw i32 0, %18
br label %40
20: ; preds = %8
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @lseek(i32 %12, i32 -4, i32 %21)
%23 = call i32 @write(i32 %12, i32* %3, i32 4)
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %12, i32 0, i32 %24)
%26 = call i64 @read(i32 %12, i32* %3, i32 4)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %20, %28
%29 = phi i32 [ %31, %28 ], [ 1437226410, %20 ]
%30 = load i32, i32* %3
%31 = sub nsw i32 %29, %30
%32 = call i64 @read(i32 %12, i32* %3, i32 4)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %28, label %34
34: ; preds = %28, %20
%35 = phi i32 [ 1437226410, %20 ], [ %31, %28 ]
store i32 %35, i32* %4
%36 = load i32, i32* @SEEK_END
%37 = tail call i32 @lseek(i32 %12, i32 -4, i32 %36)
%38 = call i32 @write(i32 %12, i32* %4, i32 4)
%39 = tail call i32 @close(i32 %12)
br label %40
40: ; preds = %34, %14
%41 = phi i32 [ %19, %14 ], [ 0, %34 ]
ret i32 %41
}