#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*/ pid_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
void *MAP_FAILED;
int MAP_SHARED;
int O_CREAT;
int O_EXCL;
int O_RDONLY;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int errno;
int getopt(int, char **, char *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ gets(char *);
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
scalar_t__ munmap(void *, size_t);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int shm_open(char *, int, int);
scalar_t__ strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int main(int argc, char **argv) {
  int perms = 0600;
  size_t size = 65536;
  int oflags = 0;
  int ropt = 0;
  int wopt = 0;
  int shm_fd;
  int mprot = PROT_READ;
  int mflags = MAP_SHARED;
  void *attach;
  char *path;
  int c;
  while (-1 != (c = getopt(argc, argv, "p:s:cxrtw"))) {
    switch (c) {
    case 'p':
      perms = (int)strtoul(optarg, NULL, 0);
      break;
    case 's':
      size = (size_t)strtoul(optarg, NULL, 0);
      break;
    case 'c':
      oflags |= O_CREAT;
      break;
    case 'x':
      oflags |= O_EXCL;
      break;
    case 't':
      oflags |= O_TRUNC;
      break;
    case 'r':
      ropt = 1;
      break;
    case 'w':
      wopt = 1;
      break;
    default:
      return -1;
    }
  }
  if (optind < argc)
    path = argv[optind];
  else {
    printf("Segment pathname required\n");
    return -1;
  }
  if (0 == ropt) {
    oflags |= O_RDWR;
    mprot |= PROT_WRITE;
  } else {
    oflags |= O_RDONLY;
  }
  shm_fd = shm_open(path, oflags, perms);
  if (-1 != shm_fd) {
    attach = mmap(NULL, size, mprot, mflags, shm_fd, (off_t)0);
    if (attach != MAP_FAILED) {
      printf("Attached at 0x%lx, first word = 0x%lx\n", attach,
             *((pid_t *)attach));
      if (mprot & PROT_WRITE) {
        *((pid_t *)attach) = getpid();
        printf("Set first word to 0x%lx\n", *((pid_t *)attach));
      }
      if (wopt) {
        char inp[80];
        printf("Waiting for return key before unmapping...");
        gets(inp);
        printf("First word is now 0x%lx\n", *((pid_t *)attach));
      }
      if (munmap(attach, size))
        perror("munmap()");
    } else
      perror("mmap()");
  } else
    perror("shm_open()");
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x180,-0x14(%rbp)
movq   $0x10000,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x4c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     12d7 <main+0x147>
mov    -0x4c(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0xa8(%rbp)
sub    $0x15,%eax
ja     12c6 <main+0x136>
mov    -0xa8(%rbp),%rax
lea    0xdd0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x14(%rbp)
jmp    12d2 <main+0x142>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %rax,-0x20(%rbp)
jmp    12d2 <main+0x142>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12d2 <main+0x142>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12d2 <main+0x142>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12d2 <main+0x142>
movl   $0x1,-0x28(%rbp)
jmp    12d2 <main+0x142>
movl   $0x1,-0x2c(%rbp)
jmp    12d2 <main+0x142>
movl   $0xffffffff,-0x4(%rbp)
jmp    1486 <main+0x2f6>
jmp    11e5 <main+0x55>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1304 <main+0x174>
mov    -0x10(%rbp),%rax
mov    0x2cbc(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
jmp    131e <main+0x18e>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1486 <main+0x2f6>
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
jne    134c <main+0x1bc>
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2c51(%rip),%rax
mov    (%rax),%eax
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    135b <main+0x1cb>
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10b0 <shm_open@plt>
mov    %eax,-0x30(%rbp)
mov    $0xffffffff,%eax
cmp    -0x30(%rbp),%eax
je     146e <main+0x2de>
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2be4(%rip),%rcx
cmp    (%rcx),%rax
je     145d <main+0x2cd>
mov    -0x40(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
lea    0xcbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
mov    0x2bc1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13fd <main+0x26d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1435 <main+0x2a5>
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1060 <gets@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <munmap@plt>
cmp    $0x0,%rax
je     1458 <main+0x2c8>
lea    0xcae(%rip),%rdi
call   1080 <perror@plt>
jmp    1469 <main+0x2d9>
lea    0xca6(%rip),%rdi
call   1080 <perror@plt>
jmp    147a <main+0x2ea>
lea    0xc9c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2b17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x180,%r12d
mov    $0x10000,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%al
mov    %eax,0x4(%rsp)
lea    0xe67(%rip),%r14
mov    0x2df8(%rip),%r15
xor    %r13d,%r13d
jmp    120f <main+0x6f>
nopl   (%rax)
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10a0 <getopt@plt>
cmp    $0x70,%eax
je     1200 <main+0x60>
lea    -0x63(%rax),%ecx
cmp    $0x15,%ecx
ja     1286 <main+0xe6>
lea    0xdd0(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    0x2db8(%rip),%rax
or     (%rax),%r13d
jmp    120f <main+0x6f>
mov    $0x1,%eax
mov    %rax,0x18(%rsp)
jmp    120f <main+0x6f>
mov    (%r15),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,0x10(%rsp)
jmp    120f <main+0x6f>
mov    0x2d7d(%rip),%rax
or     (%rax),%r13d
jmp    120f <main+0x6f>
movl   $0x0,0x4(%rsp)
jmp    120f <main+0x6f>
mov    0x2d1f(%rip),%rax
or     (%rax),%r13d
jmp    120f <main+0x6f>
cmp    $0xffffffff,%eax
jne    139a <main+0x1fa>
mov    0x2d1a(%rip),%rax
movslq (%rax),%rax
cmp    %ebx,%eax
jge    138e <main+0x1ee>
xor    %ebx,%ebx
cmpl   $0x0,0x18(%rsp)
mov    0x2ce1(%rip),%r14
cmove  (%r14),%ebx
mov    0x2cfe(%rip),%rcx
cmove  0x2cfe(%rip),%rcx
mov    0x0(%rbp,%rax,8),%rdi
or     (%rcx),%r13d
mov    %r13d,%esi
mov    %r12d,%edx
call   10c0 <shm_open@plt>
cmp    $0xffffffff,%eax
je     13ae <main+0x20e>
or     0x8(%rsp),%ebx
xor    %edi,%edi
mov    0x10(%rsp),%r15
mov    %r15,%rsi
mov    %ebx,%edx
mov    0xc(%rsp),%ecx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
mov    0x2c81(%rip),%rax
cmp    (%rax),%rbp
je     13b7 <main+0x217>
mov    0x0(%rbp),%edx
lea    0xd48(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,(%r14)
je     1343 <main+0x1a3>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x0(%rbp)
lea    0xd4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
testb  $0x1,0x4(%rsp)
jne    1373 <main+0x1d3>
lea    0xd51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%rdi
call   1070 <gets@plt>
mov    0x0(%rbp),%esi
lea    0xd61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <munmap@plt>
test   %rax,%rax
jne    13c0 <main+0x220>
mov    0x2c0e(%rip),%rax
mov    (%rax),%eax
jmp    139f <main+0x1ff>
lea    0xd6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd41(%rip),%rdi
jmp    13c7 <main+0x227>
lea    0xd31(%rip),%rdi
jmp    13c7 <main+0x227>
lea    0xd1f(%rip),%rdi
call   1090 <perror@plt>
jmp    1383 <main+0x1e3>

LLVM IR (-O0):
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str = [10 x i8] c"p:s:cxrtw\00"
@optarg = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_TRUNC = global i32 0
@optind = global i32 0
@.str.1 = [27 x i8] c"Segment pathname required\0A\00"
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@O_RDONLY = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [39 x i8] c"Attached at 0x%lx, first word = 0x%lx\0A\00"
@.str.3 = [25 x i8] c"Set first word to 0x%lx\0A\00"
@.str.4 = [43 x i8] c"Waiting for return key before unmapping...\00"
@.str.5 = [25 x i8] c"First word is now 0x%lx\0A\00"
@.str.6 = [9 x i8] c"munmap()\00"
@.str.7 = [7 x i8] c"mmap()\00"
@.str.8 = [11 x i8] c"shm_open()\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 384, i32* %6
store i64 65536, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%18 = load i32, i32* @PROT_READ
store i32 %18, i32* %12
%19 = load i32, i32* @MAP_SHARED
store i32 %19, i32* %13
br label %20
20: ; preds = %49, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %16
%24 = icmp ne i32 -1, %23
br i1 %24, label %25, label %50
25: ; preds = %20
%26 = load i32, i32* %16
switch i32 %26, label %48 [
i32 112, label %27
i32 115, label %31
i32 99, label %34
i32 120, label %38
i32 116, label %42
i32 114, label %46
i32 119, label %47
]
27: ; preds = %25
%28 = load i32, i32* @optarg
%29 = call i64 @strtoul(i32 %28, i32* null, i32 0)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %6
br label %49
31: ; preds = %25
%32 = load i32, i32* @optarg
%33 = call i64 @strtoul(i32 %32, i32* null, i32 0)
store i64 %33, i64* %7
br label %49
34: ; preds = %25
%35 = load i32, i32* @O_CREAT
%36 = load i32, i32* %8
%37 = or i32 %36, %35
store i32 %37, i32* %8
br label %49
38: ; preds = %25
%39 = load i32, i32* @O_EXCL
%40 = load i32, i32* %8
%41 = or i32 %40, %39
store i32 %41, i32* %8
br label %49
42: ; preds = %25
%43 = load i32, i32* @O_TRUNC
%44 = load i32, i32* %8
%45 = or i32 %44, %43
store i32 %45, i32* %8
br label %49
46: ; preds = %25
store i32 1, i32* %9
br label %49
47: ; preds = %25
store i32 1, i32* %10
br label %49
48: ; preds = %25
store i32 -1, i32* %3
br label %136
49: ; preds = %47, %46, %42, %38, %34, %31, %27
br label %20
50: ; preds = %20
%51 = load i32, i32* @optind
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = load i8**, i8*** %5
%56 = load i32, i32* @optind
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %15
br label %62
60: ; preds = %50
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %136
62: ; preds = %54
%63 = load i32, i32* %9
%64 = icmp eq i32 0, %63
br i1 %64, label %65, label %72
65: ; preds = %62
%66 = load i32, i32* @O_RDWR
%67 = load i32, i32* %8
%68 = or i32 %67, %66
store i32 %68, i32* %8
%69 = load i32, i32* @PROT_WRITE
%70 = load i32, i32* %12
%71 = or i32 %70, %69
store i32 %71, i32* %12
br label %76
72: ; preds = %62
%73 = load i32, i32* @O_RDONLY
%74 = load i32, i32* %8
%75 = or i32 %74, %73
store i32 %75, i32* %8
br label %76
76: ; preds = %72, %65
%77 = load i8*, i8** %15
%78 = load i32, i32* %8
%79 = load i32, i32* %6
%80 = call i32 @shm_open(i8* %77, i32 %78, i32 %79)
store i32 %80, i32* %11
%81 = load i32, i32* %11
%82 = icmp ne i32 -1, %81
br i1 %82, label %83, label %132
83: ; preds = %76
%84 = load i64, i64* %7
%85 = load i32, i32* %12
%86 = load i32, i32* %13
%87 = load i32, i32* %11
%88 = call i8* @mmap(i32* null, i64 %84, i32 %85, i32 %86, i32 %87, i32 0)
store i8* %88, i8** %14
%89 = load i8*, i8** %14
%90 = load i8*, i8** @MAP_FAILED
%91 = icmp ne i8* %89, %90
br i1 %91, label %92, label %129
92: ; preds = %83
%93 = load i8*, i8** %14
%94 = load i8*, i8** %14
%95 = bitcast i8* %94 to i32*
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %93, i32 %96)
%98 = load i32, i32* %12
%99 = load i32, i32* @PROT_WRITE
%100 = and i32 %98, %99
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %92
%103 = call i32 (...) @getpid()
%104 = load i8*, i8** %14
%105 = bitcast i8* %104 to i32*
store i32 %103, i32* %105
%106 = load i8*, i8** %14
%107 = bitcast i8* %106 to i32*
%108 = load i32, i32* %107
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %102, %92
%111 = load i32, i32* %10
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %121
113: ; preds = %110
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%115 = getelementptr inbounds [80 x i8], [80 x i8]* %17, i64 0, i64 0
%116 = call i32 @gets(i8* %115)
%117 = load i8*, i8** %14
%118 = bitcast i8* %117 to i32*
%119 = load i32, i32* %118
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %119)
br label %121
121: ; preds = %113, %110
%122 = load i8*, i8** %14
%123 = load i64, i64* %7
%124 = call i64 @munmap(i8* %122, i64 %123)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %128
126: ; preds = %121
%127 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %128
128: ; preds = %126, %121
br label %131
129: ; preds = %83
%130 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %131
131: ; preds = %129, %128
br label %134
132: ; preds = %76
%133 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %134
134: ; preds = %132, %131
%135 = load i32, i32* @errno
store i32 %135, i32* %3
br label %136
136: ; preds = %134, %60, %48
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str = [10 x i8] c"p:s:cxrtw\00"
@optarg = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_TRUNC = global i32 0
@optind = global i32 0
@O_RDWR = global i32 0
@PROT_WRITE = global i32 0
@O_RDONLY = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [39 x i8] c"Attached at 0x%lx, first word = 0x%lx\0A\00"
@.str.3 = [25 x i8] c"Set first word to 0x%lx\0A\00"
@.str.4 = [43 x i8] c"Waiting for return key before unmapping...\00"
@.str.5 = [25 x i8] c"First word is now 0x%lx\0A\00"
@.str.6 = [9 x i8] c"munmap()\00"
@.str.7 = [7 x i8] c"mmap()\00"
@.str.8 = [11 x i8] c"shm_open()\00"
@errno = global i32 0
@str = [26 x i8] c"Segment pathname required\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [80 x i8]
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @MAP_SHARED
br label %6
6: ; preds = %24, %2
%7 = phi i1 [ true, %2 ], [ false, %24 ]
%8 = phi i32 [ 0, %2 ], [ %13, %24 ]
%9 = phi i32 [ 0, %2 ], [ %18, %24 ]
%10 = phi i64 [ 65536, %2 ], [ %22, %24 ]
%11 = phi i32 [ 384, %2 ], [ %25, %24 ]
br label %12
12: ; preds = %24, %6
%13 = phi i32 [ %8, %6 ], [ 1, %24 ]
%14 = phi i32 [ %9, %6 ], [ %18, %24 ]
%15 = phi i64 [ %10, %6 ], [ %22, %24 ]
%16 = phi i32 [ %11, %6 ], [ %25, %24 ]
br label %17
17: ; preds = %36, %12
%18 = phi i32 [ %14, %12 ], [ %39, %36 ]
%19 = phi i64 [ %15, %12 ], [ %22, %36 ]
%20 = phi i32 [ %16, %12 ], [ %25, %36 ]
br label %21
21: ; preds = %17, %31
%22 = phi i64 [ %19, %17 ], [ %33, %31 ]
%23 = phi i32 [ %20, %17 ], [ %25, %31 ]
br label %24
24: ; preds = %21, %27
%25 = phi i32 [ %30, %27 ], [ %23, %21 ]
%26 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %26, label %91 [
i32 -1, label %40
i32 112, label %27
i32 115, label %31
i32 99, label %36
i32 120, label %34
i32 116, label %35
i32 114, label %12
i32 119, label %6
]
27: ; preds = %24
%28 = load i32, i32* @optarg
%29 = tail call i64 @strtoul(i32 %28, i32* null, i32 0)
%30 = trunc i64 %29 to i32
br label %24
31: ; preds = %24
%32 = load i32, i32* @optarg
%33 = tail call i64 @strtoul(i32 %32, i32* null, i32 0)
br label %21
34: ; preds = %24
br label %36
35: ; preds = %24
br label %36
36: ; preds = %24, %35, %34
%37 = phi i32* [ @O_EXCL, %34 ], [ @O_TRUNC, %35 ], [ @O_CREAT, %24 ]
%38 = load i32, i32* %37
%39 = or i32 %38, %18
br label %17
40: ; preds = %24
%41 = load i32, i32* @optind
%42 = icmp slt i32 %41, %0
br i1 %42, label %43, label %57
43: ; preds = %40
%44 = sext i32 %41 to i64
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = icmp eq i32 %13, 0
%48 = load i32, i32* @PROT_WRITE
%49 = select i1 %47, i32 %48, i32 0
%50 = or i32 %49, %4
%51 = load i32, i32* @O_RDWR
%52 = load i32, i32* @O_RDONLY
%53 = select i1 %47, i32 %51, i32 %52
%54 = or i32 %53, %18
%55 = tail call i32 @shm_open(i8* %46, i32 %54, i32 %25)
%56 = icmp eq i32 %55, -1
br i1 %56, label %87, label %59
57: ; preds = %40
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %91
59: ; preds = %43
%60 = tail call i8* @mmap(i32* null, i64 %22, i32 %50, i32 %5, i32 %55, i32 0)
%61 = load i8*, i8** @MAP_FAILED
%62 = icmp eq i8* %60, %61
br i1 %62, label %85, label %63
63: ; preds = %59
%64 = bitcast i8* %60 to i32*
%65 = load i32, i32* %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %60, i32 %65)
%67 = load i32, i32* @PROT_WRITE
%68 = and i32 %67, %50
%69 = icmp eq i32 %68, 0
br i1 %69, label %73, label %70
70: ; preds = %63
%71 = tail call i32 (...) @getpid()
store i32 %71, i32* %64
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %63
br i1 %7, label %80, label %74
74: ; preds = %73
%75 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%77 = call i32 @gets(i8* %75)
%78 = load i32, i32* %64
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %74, %73
%81 = call i64 @munmap(i8* %60, i64 %22)
%82 = icmp eq i64 %81, 0
br i1 %82, label %89, label %83
83: ; preds = %80
%84 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %89
85: ; preds = %59
%86 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %89
87: ; preds = %43
%88 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %89
89: ; preds = %85, %83, %80, %87
%90 = load i32, i32* @errno
br label %91
91: ; preds = %24, %89, %57
%92 = phi i32 [ %90, %89 ], [ -1, %57 ], [ -1, %24 ]
ret i32 %92
}