#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int fw, count, crc;
  char buf[28];
  fw = open(argv[1], O_RDWR);
  read(fw, &buf, 28);
  for (count = 0, crc = 0; count < 7; count++) {
    crc += *((int *)(buf + count * 4));
  }
  crc = (~crc) + 1;
  lseek(fw, 0x0000001C, SEEK_SET);
  write(fw, &crc, 4);
  close(fw);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1c,%edx
call   1060 <read@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x7,-0x18(%rbp)
jge    11c8 <main+0x78>
mov    -0x18(%rbp),%eax
shl    $0x2,%eax
cltq
mov    -0x40(%rbp,%rax,1),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119e <main+0x4e>
mov    -0x1c(%rbp),%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    $0x1c,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x1c,%edx
call   1060 <read@plt>
mov    0x10(%rsp),%eax
add    0x14(%rsp),%eax
add    0x18(%rsp),%eax
add    0x1c(%rsp),%eax
add    0x20(%rsp),%eax
add    0x24(%rsp),%eax
add    0x28(%rsp),%eax
neg    %eax
mov    %eax,0xc(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x1c,%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>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [28 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 0
%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 = bitcast [28 x i8]* %4 to i8**
%12 = call i32 @read(i32 %10, i8** %11, i32 28)
%13 = bitcast [28 x i8]* %4 to i32*
%14 = load i32, i32* %13
%15 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 4
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = add nsw i32 %14, %17
%19 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 8
%20 = bitcast i8* %19 to i32*
%21 = load i32, i32* %20
%22 = add nsw i32 %18, %21
%23 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 12
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = add nsw i32 %22, %25
%27 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 16
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = add nsw i32 %26, %29
%31 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 20
%32 = bitcast i8* %31 to i32*
%33 = load i32, i32* %32
%34 = add nsw i32 %30, %33
%35 = getelementptr inbounds [28 x i8], [28 x i8]* %4, i64 0, i64 24
%36 = bitcast i8* %35 to i32*
%37 = load i32, i32* %36
%38 = add nsw i32 %34, %37
%39 = sub i32 0, %38
store i32 %39, i32* %3
%40 = load i32, i32* @SEEK_SET
%41 = tail call i32 @lseek(i32 %10, i32 28, i32 %40)
%42 = call i32 @write(i32 %10, i32* %3, i32 4)
%43 = tail call i32 @close(i32 %10)
ret i32 0
}