#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, int *, int);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  int fd;
  uint32_t tmp, chk, n;
  chk = 0;
  if (argc != 2)
    return -1;
  if ((fd = open(argv[1], O_RDWR)) < 0)
    return -1;
  for (n = 0; n < 7; n++) {
    if (read(fd, &tmp, 4) != 4)
      return -1;
    chk += tmp;
  }
  tmp = -chk;
  n = write(fd, &tmp, 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,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1173 <main+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a1 <main+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <main+0xda>
movl   $0x0,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jge    11ef <main+0xaf>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     11d8 <main+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <main+0xda>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a8 <main+0x68>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jne    1285 <main+0x145>
mov    0x8(%rsi),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1285 <main+0x145>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    0xc(%rsp),%r14d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    0xc(%rsp),%r15d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    0xc(%rsp),%r12d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    0xc(%rsp),%r13d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    0xc(%rsp),%eax
mov    %eax,0x14(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
mov    %r13d,0x10(%rsp)
mov    0xc(%rsp),%r13d
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1285 <main+0x145>
add    %r14d,%r15d
add    %r15d,%r12d
mov    0x10(%rsp),%eax
add    %r12d,%eax
mov    0x14(%rsp),%ecx
add    %eax,%ecx
add    %ecx,%r13d
add    0xc(%rsp),%r13d
neg    %r13d
mov    %r13d,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = 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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %44
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 -1, i32* %3
br label %44
21: ; preds = %13
store i32 0, i32* %9
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 7
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32, i32* %6
%27 = call i32 @read(i32 %26, i32* %7, i32 4)
%28 = icmp ne i32 %27, 4
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %3
br label %44
30: ; preds = %25
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = add nsw i32 %32, %31
store i32 %33, i32* %8
br label %34
34: ; preds = %30
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %22
37: ; preds = %22
%38 = load i32, i32* %8
%39 = sub nsw i32 0, %38
store i32 %39, i32* %7
%40 = load i32, i32* %6
%41 = call i32 @write(i32 %40, i32* %7, i32 4)
store i32 %41, i32* %9
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %37, %29, %20, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %50
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %50, label %12
12: ; preds = %6
%13 = call i32 @read(i32 %10, i32* %3, i32 4)
%14 = icmp eq i32 %13, 4
br i1 %14, label %15, label %50
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i32 @read(i32 %10, i32* %3, i32 4)
%18 = icmp eq i32 %17, 4
br i1 %18, label %19, label %50
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @read(i32 %10, i32* %3, i32 4)
%22 = icmp eq i32 %21, 4
br i1 %22, label %23, label %50
23: ; preds = %19
%24 = load i32, i32* %3
%25 = call i32 @read(i32 %10, i32* %3, i32 4)
%26 = icmp eq i32 %25, 4
br i1 %26, label %27, label %50
27: ; preds = %23
%28 = load i32, i32* %3
%29 = call i32 @read(i32 %10, i32* %3, i32 4)
%30 = icmp eq i32 %29, 4
br i1 %30, label %31, label %50
31: ; preds = %27
%32 = load i32, i32* %3
%33 = call i32 @read(i32 %10, i32* %3, i32 4)
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %3
%37 = call i32 @read(i32 %10, i32* %3, i32 4)
%38 = icmp eq i32 %37, 4
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = add nsw i32 %20, %16
%41 = add nsw i32 %24, %40
%42 = add nsw i32 %28, %41
%43 = add nsw i32 %32, %42
%44 = add nsw i32 %36, %43
%45 = load i32, i32* %3
%46 = add nsw i32 %45, %44
%47 = sub nsw i32 0, %46
store i32 %47, i32* %3
%48 = call i32 @write(i32 %10, i32* %3, i32 4)
%49 = tail call i32 @close(i32 %10)
br label %50
50: ; preds = %12, %15, %19, %23, %27, %31, %35, %6, %2, %39
%51 = phi i32 [ 0, %39 ], [ -1, %2 ], [ -1, %6 ], [ -1, %35 ], [ -1, %31 ], [ -1, %27 ], [ -1, %23 ], [ -1, %19 ], [ -1, %15 ], [ -1, %12 ]
ret i32 %51
}