#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 /*<<< orphan*/ PROT_READ;
scalar_t__ mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
                int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int shm_open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int main(int argc, char **argv) {
  int fd;
  char word[1024];
  fd = shm_open("/test", O_RDWR, 0);
  if (fd == -1) {
    perror("shm_open");
    return 1;
  }
  char *p = (char *)mmap(0, 10240, PROT_READ, MAP_SHARED, fd, 0);
  sscanf(p, "%1023s", word);
  printf("%s", word);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
xor    %edx,%edx
call   1070 <shm_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a5 <main+0x55>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <main+0xb6>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x2800,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1050 <sscanf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
xor    %edx,%edx
call   1070 <shm_open@plt>
cmp    $0xffffffff,%eax
je     11ca <main+0x7a>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e64(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x2800,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
lea    0xe70(%rip),%rsi
mov    %rsp,%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
jmp    11bc <main+0x6c>

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

LLVM IR (-O2):
@.str = [6 x i8] c"/test\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.2 = [7 x i8] c"%1023s\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @shm_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %17
10: ; preds = %2
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_SHARED
%13 = tail call i64 @mmap(i32 0, i32 10240, i32 %11, i32 %12, i32 %6, i32 0)
%14 = inttoptr i64 %13 to i8*
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %17
17: ; preds = %10, %8
ret i32 1
}