#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*/ buf;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
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.");
  ;
  printf("Please Input Data:");
  memset(buf, 0, sizeof(buf));
  scanf("%s", buf);
  memcpy(pmat + no * 1024, buf, 1024);
  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    0x2e37(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1234,%edi
mov    $0x2800,%esi
call   10a0 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11ec <main+0x6c>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
lea    0xe31(%rip),%rdx
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1340 <main+0x1c0>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
lea    0xe09(%rip),%rdx
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1090 <shmat@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    124a <main+0xca>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
lea    0xdf1(%rip),%rdx
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1340 <main+0x1c0>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
lea    0xdc9(%rip),%rdx
call   1060 <fprintf@plt>
lea    0xdc6(%rip),%rdi
call   1040 <printf@plt>
lea    0xdd1(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jl     1298 <main+0x118>
cmpl   $0x9,-0xc(%rbp)
jle    12c0 <main+0x140>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
lea    0xd9e(%rip),%rdx
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1340 <main+0x1c0>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
lea    0xd76(%rip),%rdx
call   1060 <fprintf@plt>
lea    0xd74(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x420(%rbp),%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
cltq
add    %rax,%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <memcpy@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    0x2e47(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1234,%edi
mov    $0x2800,%esi
call   10a0 <shmget@plt>
mov    0x2e32(%rip),%r14
mov    (%r14),%edi
cmp    $0xffffffff,%eax
je     1235 <main+0xb5>
mov    %eax,%ebx
lea    0xe5e(%rip),%rsi
lea    0xe46(%rip),%rdx
call   1060 <fprintf@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <shmat@plt>
mov    (%r14),%edi
test   %rax,%rax
je     124a <main+0xca>
mov    %rax,%rbx
lea    0xe35(%rip),%rsi
lea    0xe3b(%rip),%rdx
call   1060 <fprintf@plt>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
lea    0xe43(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmpl   $0xa,0xc(%rsp)
mov    (%r14),%edi
jb     125f <main+0xdf>
lea    0xddc(%rip),%rsi
lea    0xe22(%rip),%rdx
call   1060 <fprintf@plt>
jmp    12c4 <main+0x144>
lea    0xdc4(%rip),%rsi
lea    0xdc9(%rip),%rdx
call   1060 <fprintf@plt>
jmp    12c4 <main+0x144>
lea    0xdaf(%rip),%rsi
lea    0xdd2(%rip),%rdx
call   1060 <fprintf@plt>
jmp    12c4 <main+0x144>
lea    0xdb7(%rip),%rsi
lea    0xde0(%rip),%rdx
call   1060 <fprintf@plt>
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xdd1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movslq 0xc(%rsp),%rdi
shl    $0xa,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1070 <memcpy@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 = [19 x i8] c"Please Input Data:\00"
@.str.8 = [3 x i8] c"%s\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 %56
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 %56
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 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @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 %56
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 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 1024)
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%46 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %4
%48 = load i32, i32* %3
%49 = mul nsw i32 %48, 1024
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%53 = call i32 @memcpy(i8* %51, i8* %52, i32 1024)
%54 = load i8*, i8** %4
%55 = call i32 @shmdt(i8* %54)
store i32 0, i32* %1
br label %56
56: ; preds = %41, %35, %21, %10
%57 = load i32, i32* %1
ret i32 %57
}

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 = [19 x i8] c"Please Input Data:\00"
@.str.8 = [3 x i8] c"%s\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 %40
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 %40
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 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (i8*, ...) @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 %40
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 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 @memset(i8* %4, i32 0, i32 1024)
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%34 = load i32, i32* %1
%35 = shl nsw i32 %34, 10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %15, i64 %36
%38 = call i32 @memcpy(i8* %37, i8* %4, i32 1024)
%39 = call i32 @shmdt(i8* %15)
br label %40
40: ; preds = %29, %27, %18, %10
ret i32 0
}