#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_PRIVATE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PROT_EXEC;
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int fd, len, offset, pn;
  void *s;
  fd = open("scanff.c", O_RDWR);
  if (fd == -1) {
    perror("open failed");
    return -1;
  }
  s = mmap(NULL, 10, PROT_EXEC, MAP_PRIVATE, fd, 0);
  if (s == (void *)-1) {
    perror("mmap failed");
    return -1;
  }
  printf("%10s%n", (char *)s, &pn);
  printf("%d\n", pn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1189 <main+0x49>
lea    0xe91(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
jne    11dd <main+0x9d>
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <main+0xcb>
mov    -0x20(%rbp),%rsi
lea    0xe39(%rip),%rdi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11bb <main+0x7b>
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e61(%rip),%rcx
mov    (%rcx),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0xa,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     11c4 <main+0x84>
lea    0xe8f(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe47(%rip),%rdi
jmp    11cb <main+0x8b>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11b3 <main+0x73>

LLVM IR (-O0):
@.str = [9 x i8] c"scanff.c\00"
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"open failed\00"
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [12 x i8] c"mmap failed\00"
@.str.3 = [7 x i8] c"%10s%n\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
13: ; preds = %0
%14 = load i32, i32* @PROT_EXEC
%15 = load i32, i32* @MAP_PRIVATE
%16 = load i32, i32* %2
%17 = call i8* @mmap(i32* null, i32 10, i32 %14, i32 %15, i32 %16, i32 0)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, inttoptr (i64 -1 to i8*)
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
22: ; preds = %13
%23 = load i8*, i8** %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %23, i32* %5)
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %25)
store i32 0, i32* %1
br label %27
27: ; preds = %22, %20, %11
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [9 x i8] c"scanff.c\00"
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"open failed\00"
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [12 x i8] c"mmap failed\00"
@.str.3 = [7 x i8] c"%10s%n\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = load i32, i32* @PROT_EXEC
%10 = load i32, i32* @MAP_PRIVATE
%11 = tail call i8* @mmap(i32* null, i32 10, i32 %9, i32 %10, i32 %4, i32 0)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32* %1)
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %13, %6
%20 = phi i32 [ -1, %6 ], [ -1, %13 ], [ 0, %15 ]
ret i32 %20
}