#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 IPC_CREAT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int shmget(int, int, int);
int /*<<< orphan*/ stderr;
int main() {
  int shmid, no;
  char *pmat = NULL, buf[1024];
  if ((shmid = shmget(0x1234, 10 * 1024, 0666 | IPC_CREAT)) == -1) {
    fprintf(stderr, "%s failed.\n", "Open(Create) Shm");
    return 0;
  } else
    fprintf(stderr, "%s success.\n", "Open(Create) Shm");
  ;
  if ((pmat = (char *)shmat(shmid, 0, 0)) == 0) {
    fprintf(stderr, "%s failed.\n", "Link Shm");
    return 0;
  } else
    fprintf(stderr, "%s success.\n", "Link Shm");
  ;
  printf("Please Input No.(0-9):");
  scanf("%d", &no);
  if (no < 0 || no > 9) {
    fprintf(stderr, "%s failed.\n", "Input No.");
    return 0;
  } else
    fprintf(stderr, "%s success.\n", "Input No.");
  ;
  memcpy(buf, pmat + no * 1024, 1024);
  printf("Data:[%s]\n", buf);
  shmdt(pmat);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1234,%edi
mov    $0x2800,%esi
call   1090 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11dc <main+0x6c>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
lea    0xe41(%rip),%rdx
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
lea    0xe19(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <shmat@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    123a <main+0xca>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
lea    0xe01(%rip),%rdx
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
lea    0xdd9(%rip),%rdx
call   1050 <fprintf@plt>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jl     1288 <main+0x118>
cmpl   $0x9,-0xc(%rbp)
jle    12b0 <main+0x140>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
lea    0xdae(%rip),%rdx
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x1a1>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
lea    0xd86(%rip),%rdx
call   1050 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
cltq
add    %rax,%rsi
mov    $0x400,%edx
call   1060 <memcpy@plt>
lea    -0x420(%rbp),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <shmdt@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    0x2e57(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1234,%edi
mov    $0x2800,%esi
call   1090 <shmget@plt>
mov    0x2e42(%rip),%r14
mov    (%r14),%edi
cmp    $0xffffffff,%eax
je     1222 <main+0xb2>
mov    %eax,%ebx
lea    0xe6e(%rip),%rsi
lea    0xe56(%rip),%rdx
call   1050 <fprintf@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
mov    (%r14),%edi
test   %rax,%rax
je     1237 <main+0xc7>
mov    %rax,%rbx
lea    0xe45(%rip),%rsi
lea    0xe4b(%rip),%rdx
call   1050 <fprintf@plt>
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
cmpl   $0xa,0xc(%rsp)
mov    (%r14),%edi
jb     124c <main+0xdc>
lea    0xdec(%rip),%rsi
lea    0xe32(%rip),%rdx
call   1050 <fprintf@plt>
jmp    1296 <main+0x126>
lea    0xdd7(%rip),%rsi
lea    0xddc(%rip),%rdx
call   1050 <fprintf@plt>
jmp    1296 <main+0x126>
lea    0xdc2(%rip),%rsi
lea    0xde5(%rip),%rdx
call   1050 <fprintf@plt>
jmp    1296 <main+0x126>
lea    0xdca(%rip),%rsi
lea    0xdf3(%rip),%rdx
call   1050 <fprintf@plt>
movslq 0xc(%rsp),%rsi
shl    $0xa,%rsi
add    %rbx,%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%edx
call   1060 <memcpy@plt>
lea    0xdd3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"%s failed.\0A\00"
@.str.1 = [17 x i8] c"Open(Create) Shm\00"
@.str.2 = [13 x i8] c"%s success.\0A\00"
@.str.3 = [9 x i8] c"Link Shm\00"
@.str.4 = [23 x i8] c"Please Input No.(0-9):\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [10 x i8] c"Input No.\00"
@.str.7 = [11 x i8] c"Data:[%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1024 x i8]
store i32 0, i32* %1
store i8* null, i8** %4
%6 = load i32, i32* @IPC_CREAT
%7 = or i32 438, %6
%8 = call i32 @shmget(i32 4660, i32 10240, i32 %7)
store i32 %8, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %53
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13
%17 = load i32, i32* %2
%18 = call i64 @shmat(i32 %17, i32 0, i32 0)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %53
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* %3
%34 = icmp sgt i32 %33, 9
br i1 %34, label %35, label %38
35: ; preds = %32, %27
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %53
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %41
41: ; preds = %38
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = load i8*, i8** %4
%44 = load i32, i32* %3
%45 = mul nsw i32 %44, 1024
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = call i32 @memcpy(i8* %42, i8* %47, i32 1024)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %4
%52 = call i32 @shmdt(i8* %51)
store i32 0, i32* %1
br label %53
53: ; preds = %41, %35, %21, %10
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"%s failed.\0A\00"
@.str.1 = [17 x i8] c"Open(Create) Shm\00"
@.str.2 = [13 x i8] c"%s success.\0A\00"
@.str.3 = [9 x i8] c"Link Shm\00"
@.str.4 = [23 x i8] c"Please Input No.(0-9):\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [10 x i8] c"Input No.\00"
@.str.7 = [11 x i8] c"Data:[%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @IPC_CREAT
%6 = or i32 %5, 438
%7 = tail call i32 @shmget(i32 4660, i32 10240, i32 %6)
%8 = icmp eq i32 %7, -1
%9 = load i32, i32* @stderr
br i1 %8, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %38
12: ; preds = %0
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i64 @shmat(i32 %7, i32 0, i32 0)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
%17 = load i32, i32* @stderr
br i1 %16, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %38
20: ; preds = %12
%21 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%24 = load i32, i32* %1
%25 = icmp ugt i32 %24, 9
%26 = load i32, i32* @stderr
br i1 %25, label %27, label %29
27: ; preds = %20
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %38
29: ; preds = %20
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32, i32* %1
%32 = shl nsw i32 %31, 10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %15, i64 %33
%35 = call i32 @memcpy(i8* %4, i8* %34, i32 1024)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%37 = call i32 @shmdt(i8* %15)
br label %38
38: ; preds = %29, %27, %18, %10
ret i32 0
}