#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *const, int, int);
int random_range(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *const argv[]) {
  int fd;
  void *file_memory;
  srand(time(NULL));
  fd = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  lseek(fd, 0x100 + 1, SEEK_SET);
  write(fd, "", 1);
  lseek(fd, 0, SEEK_SET);
  file_memory = mmap(0, 0x100, PROT_WRITE, MAP_SHARED, fd, 0);
  close(fd);
  sprintf((char *)file_memory, "%d\n", random_range(-100, 100));
  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)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    0x2de0(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
mov    $0x101,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xde9(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
mov    0x2da1(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x100,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0xffffff9c,%edi
mov    $0x64,%esi
call   1080 <random_range@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xd73(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x100,%esi
call   10a0 <munmap@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    0x8(%rbx),%rdi
mov    0x2e18(%rip),%rax
mov    0x2e31(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dde(%rip),%rax
mov    0x2df7(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,%ebx
mov    0x2dd5(%rip),%r14
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x101,%esi
call   1050 <lseek@plt>
lea    0xe02(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    (%r14),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
mov    0x2dbf(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x100,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffff9c,%edi
mov    $0x64,%esi
call   1080 <random_range@plt>
lea    0xda3(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   10c0 <sprintf@plt>
mov    %r14,%rdi
mov    $0x100,%esi
call   10a0 <munmap@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_SET = global i32 0
@.str = [1 x i8] zeroinitializer
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%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 = load i32, i32* @O_CREAT
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %12, i32 %15, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 257, i32 %21)
%23 = load i32, i32* %6
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @lseek(i32 %25, i32 0, i32 %26)
%28 = load i32, i32* @PROT_WRITE
%29 = load i32, i32* @MAP_SHARED
%30 = load i32, i32* %6
%31 = call i8* @mmap(i32 0, i32 256, i32 %28, i32 %29, i32 %30, i32 0)
store i8* %31, i8** %7
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i8*, i8** %7
%35 = call i32 @random_range(i32 -100, i32 100)
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %7
%38 = call i32 @munmap(i8* %37, i32 256)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_SET = global i32 0
@.str = [1 x i8] zeroinitializer
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* %6, i32 %9, i32 %12)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @lseek(i32 %13, i32 257, i32 %14)
%16 = tail call i32 @write(i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @lseek(i32 %13, i32 0, i32 %17)
%19 = load i32, i32* @PROT_WRITE
%20 = load i32, i32* @MAP_SHARED
%21 = tail call i8* @mmap(i32 0, i32 256, i32 %19, i32 %20, i32 %13, i32 0)
%22 = tail call i32 @close(i32 %13)
%23 = tail call i32 @random_range(i32 -100, i32 100)
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = tail call i32 @munmap(i8* %21, i32 256)
ret i32 0
}