#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*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
void *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *const, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(void *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(int argc, char *const argv[]) {
  int fd;
  void *file_memory;
  int integer;
  fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR);
  file_memory = mmap(0, 0x100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  close(fd);
  scanf(file_memory, "%d", &integer);
  printf("value: %d\n", integer);
  sprintf((char *)file_memory, "%d\n", 2 * integer);
  munmap(file_memory, 0x100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    0x2e29(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    0x2dff(%rip),%rax
or     (%rax),%edx
mov    0x2e1e(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x100,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rdi
lea    0xe09(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <scanf@plt>
mov    -0x24(%rbp),%esi
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
shl    $0x1,%edx
lea    0xdea(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x100,%esi
call   1060 <munmap@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e31(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,%ebp
mov    0x2e58(%rip),%rax
mov    0x2e19(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x100,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe29(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    0x4(%rsp),%edx
add    %edx,%edx
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <munmap@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"value: %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %11, i32 %12, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %17, %18
%20 = load i32, i32* @MAP_SHARED
%21 = load i32, i32* %6
%22 = call i8* @mmap(i32 0, i32 256, i32 %19, i32 %20, i32 %21, i32 0)
store i8* %22, i8** %7
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
%25 = load i8*, i8** %7
%26 = call i32 @scanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%27 = load i32, i32* %8
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = mul nsw i32 2, %30
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %7
%34 = call i32 @munmap(i8* %33, i32 256)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"value: %d\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %6, i32 %7, i32 %10)
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_SHARED
%16 = tail call i8* @mmap(i32 0, i32 256, i32 %14, i32 %15, i32 %11, i32 0)
%17 = tail call i32 @close(i32 %11)
%18 = call i32 @scanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = shl nsw i32 %21, 1
%23 = call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 @munmap(i8* %16, i32 256)
ret i32 0
}