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

/* Variables and functions */
int EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
int error(char *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  void *map;
  uint32_t *data;
  uint32_t sum = 0;
  int i;
  if (argc != 2) {
    fprintf(stderr, "%s: pass a binary filename please\n", argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0)
    return error(argv[0], argv[1], strerror(errno));
  map = mmap(NULL, 0x20, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (map == MAP_FAILED)
    return error(argv[0], argv[1], strerror(errno));
  data = map;
  for (i = 0; i < 7; i++)
    sum += data[i];
  data[i] = -sum;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x4f>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d8 <main+0x188>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ff <main+0xaf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    12d8 <main+0x188>
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    0x2da9(%rip),%rax
or     (%rax),%edx
mov    0x2dd0(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x20,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d6a(%rip),%rcx
cmp    (%rcx),%rax
jne    1284 <main+0x134>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    12d8 <main+0x188>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x7,-0x30(%rbp)
jge    12bc <main+0x16c>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1293 <main+0x143>
xor    %edx,%edx
sub    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11d3 <main+0x83>
mov    0x8(%rbx),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11f8 <main+0xa8>
mov    0x2e7b(%rip),%rcx
mov    0x2e34(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e59(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x20,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
je     11f8 <main+0xa8>
mov    0x4(%rax),%ecx
add    (%rax),%ecx
add    0x8(%rax),%ecx
add    0xc(%rax),%ecx
add    0x10(%rax),%ecx
add    0x14(%rax),%ecx
add    0x18(%rax),%ecx
neg    %ecx
mov    %ecx,0x1c(%rax)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
jmp    11f0 <main+0xa0>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <error@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"%s: pass a binary filename please\0A\00"
@O_RDWR = global i32 0
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %82
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @error(i8* %30, i8* %33, i8* %35)
store i32 %36, i32* %3
br label %82
37: ; preds = %19
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %38, %39
%41 = load i32, i32* @MAP_SHARED
%42 = load i32, i32* %6
%43 = call i8* @mmap(i32* null, i32 32, i32 %40, i32 %41, i32 %42, i32 0)
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = load i8*, i8** @MAP_FAILED
%46 = icmp eq i8* %44, %45
br i1 %46, label %47, label %57
47: ; preds = %37
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @error(i8* %50, i8* %53, i8* %55)
store i32 %56, i32* %3
br label %82
57: ; preds = %37
%58 = load i8*, i8** %7
%59 = bitcast i8* %58 to i32*
store i32* %59, i32** %8
store i32 0, i32* %10
br label %60
60: ; preds = %71, %57
%61 = load i32, i32* %10
%62 = icmp slt i32 %61, 7
br i1 %62, label %63, label %74
63: ; preds = %60
%64 = load i32*, i32** %8
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = load i32, i32* %9
%70 = add nsw i32 %69, %68
store i32 %70, i32* %9
br label %71
71: ; preds = %63
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %60
74: ; preds = %60
%75 = load i32, i32* %9
%76 = sub nsw i32 0, %75
%77 = load i32*, i32** %8
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 %76, i32* %80
%81 = load i32, i32* @EXIT_SUCCESS
store i32 %81, i32* %3
br label %82
82: ; preds = %74, %47, %27, %13
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"%s: pass a binary filename please\0A\00"
@O_RDWR = global i32 0
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %65
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 slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i8*, i8** %1
%16 = load i8*, i8** %9
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @error(i8* %15, i8* %16, i8* %18)
br label %65
20: ; preds = %8
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @PROT_WRITE
%23 = or i32 %22, %21
%24 = load i32, i32* @MAP_SHARED
%25 = tail call i8* @mmap(i32* null, i32 32, i32 %23, i32 %24, i32 %12, i32 0)
%26 = load i8*, i8** @MAP_FAILED
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = load i8*, i8** %1
%30 = load i8*, i8** %9
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 @error(i8* %29, i8* %30, i8* %32)
br label %65
34: ; preds = %20
%35 = bitcast i8* %25 to i32*
%36 = load i32, i32* %35
%37 = getelementptr inbounds i8, i8* %25, i64 4
%38 = bitcast i8* %37 to i32*
%39 = load i32, i32* %38
%40 = add nsw i32 %39, %36
%41 = getelementptr inbounds i8, i8* %25, i64 8
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
%44 = add nsw i32 %43, %40
%45 = getelementptr inbounds i8, i8* %25, i64 12
%46 = bitcast i8* %45 to i32*
%47 = load i32, i32* %46
%48 = add nsw i32 %47, %44
%49 = getelementptr inbounds i8, i8* %25, i64 16
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = add nsw i32 %51, %48
%53 = getelementptr inbounds i8, i8* %25, i64 20
%54 = bitcast i8* %53 to i32*
%55 = load i32, i32* %54
%56 = add nsw i32 %55, %52
%57 = getelementptr inbounds i8, i8* %25, i64 24
%58 = bitcast i8* %57 to i32*
%59 = load i32, i32* %58
%60 = add nsw i32 %59, %56
%61 = sub nsw i32 0, %60
%62 = getelementptr inbounds i8, i8* %25, i64 28
%63 = bitcast i8* %62 to i32*
store i32 %61, i32* %63
%64 = load i32, i32* @EXIT_SUCCESS
br label %65
65: ; preds = %34, %28, %14, %4
%66 = phi i32 [ 1, %4 ], [ %19, %14 ], [ %33, %28 ], [ %64, %34 ]
ret i32 %66
}