#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 */
struct shmid_ds {
  int dummy;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ last_str;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
char getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int /*<<< orphan*/ shmdt(char *);
int shmget(int, int, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int);
int main() {
  int shmid;
  char *shmptr;
  struct shmid_ds shmbuf;
  shmid = shmget(114, 1024, (IPC_CREAT | 0777));
  if (shmid == -1) {
    printf("shmget error\n");
    fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
    exit(1);
  }
  shmptr = (char *)(shmat(shmid, 0, 0));
  if ((int)shmptr == -1) {
    printf("shmat error\n");
    fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
    if (shmctl(shmid, IPC_RMID, &shmbuf) < 0) {
      perror("shmctl error\n");
      fprintf(stderr, "Error: %d - %s\n", errno, strerror(errno));
    }
    exit(1);
  }
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    printf("fork error\n");
    exit(1);
  }
  if (pid == 0) {
    int c_shmid;
    char *c_shmptr;
    struct shmid_ds c_shmbuf;
    char last_str[1024];
    memset(last_str, 0, sizeof(last_str));
    if ((c_shmid = shmget(114, 1024, IPC_CREAT)) == -1) {
      printf("fork shmget error\n");
      exit(1);
    }
    c_shmptr = (char *)shmat(c_shmid, 0, 0);
    if ((int)c_shmptr == -1) {
      printf("fork: shmat error\n");
      exit(1);
    }
    while (1) {
      if (strcmp(last_str, c_shmptr) != 0) {
        printf("fork: %s %s\n", last_str, c_shmptr);
        strcpy(last_str, c_shmptr);
      }
      if (strcmp(c_shmptr, "quit") == 0)
        break;
    }
    shmdt(c_shmptr);
    if (shmctl(c_shmid, IPC_RMID, &c_shmbuf) < 0) {
      perror("fork: close shared memroy error\n");
    }
    exit(1);
  }
  strcpy(shmptr, "this is a test.\n");
  while (1) {
    printf("Please input:\n");
    scanf("%s", shmptr);
    while (getchar() != '\n')
      ;
    if (strcmp(shmptr, "quit") == 0)
      break;
  }
  shmdt(shmptr);
  if (shmctl(shmid, IPC_RMID, &shmbuf) < 0) {
    perror("close shared memory error\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    $0x72,%edi
mov    $0x400,%esi
call   10e0 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    128c <main+0x9c>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x448(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x444(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x448(%rbp),%edi
mov    -0x444(%rbp),%edx
mov    %rax,%rcx
lea    0xd83(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10d0 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0xffffffff,%eax
jne    137a <main+0x18a>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x450(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x450(%rbp),%edi
mov    -0x44c(%rbp),%edx
mov    %rax,%rcx
lea    0xd07(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   10b0 <shmctl@plt>
cmp    $0x0,%rax
jge    1370 <main+0x180>
lea    0xcec(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x458(%rbp)
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x454(%rbp)
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x458(%rbp),%edi
mov    -0x454(%rbp),%edx
mov    %rax,%rcx
lea    0xc95(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    13a8 <main+0x1b8>
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    14e1 <main+0x2f1>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edx
mov    $0x72,%edi
mov    $0x400,%esi
call   10e0 <shmget@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1402 <main+0x212>
lea    0xc39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10d0 <shmat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    $0xffffffff,%eax
jne    1437 <main+0x247>
lea    0xc17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    143c <main+0x24c>
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     147f <main+0x28f>
lea    -0x440(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xbe8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xbd3(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    149e <main+0x2ae>
jmp    14a3 <main+0x2b3>
jmp    143c <main+0x24c>
mov    -0x30(%rbp),%rdi
call   1040 <shmdt@plt>
mov    -0x24(%rbp),%edi
mov    0x2b1a(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   10b0 <shmctl@plt>
cmp    $0x0,%rax
jge    14d7 <main+0x2e7>
lea    0xb90(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xb97(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xb9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xb99(%rip),%rdi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1527 <main+0x337>
jmp    150f <main+0x31f>
mov    -0x10(%rbp),%rdi
lea    0xb2b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1546 <main+0x356>
jmp    154b <main+0x35b>
jmp    14f1 <main+0x301>
mov    -0x10(%rbp),%rdi
call   1040 <shmdt@plt>
mov    -0x8(%rbp),%edi
mov    0x2a72(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   10b0 <shmctl@plt>
cmp    $0x0,%rax
jge    157f <main+0x38f>
lea    0xb2c(%rip),%rdi
call   10c0 <perror@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    0x2db2(%rip),%rbp
mov    $0x1ff,%edx
or     0x0(%rbp),%edx
mov    $0x72,%edi
mov    $0x400,%esi
call   10f0 <shmget@plt>
cmp    $0xffffffff,%eax
je     130e <main+0x10e>
mov    %eax,%r14d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <shmat@plt>
mov    %rax,%rbx
cmp    $0xffffffff,%ebx
je     1350 <main+0x150>
xor    %eax,%eax
call   1120 <fork@plt>
test   %rax,%rax
js     13dd <main+0x1dd>
je     13e6 <main+0x1e6>
lea    0xde4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe04(%rip),%r15
lea    0xddf(%rip),%r12
lea    0xda1(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%al
jne    12b0 <main+0xb0>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1290 <main+0x90>
mov    %rbx,%rdi
call   1050 <shmdt@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   10c0 <shmctl@plt>
test   %rax,%rax
js     1300 <main+0x100>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5e(%rip),%rdi
call   10d0 <perror@plt>
jmp    12ee <main+0xee>
lea    0xd90(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%ebx
mov    0x2cae(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1110 <strerror@plt>
lea    0xcc6(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd3d(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c7d(%rip),%r15
mov    (%r15),%ebx
mov    0x2c6b(%rip),%r12
mov    (%r12),%ebp
mov    %ebp,%edi
call   1110 <strerror@plt>
lea    0xc81(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   10a0 <fprintf@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   10c0 <shmctl@plt>
test   %rax,%rax
jns    13d3 <main+0x1d3>
lea    0xc63(%rip),%rdi
call   10d0 <perror@plt>
mov    (%r15),%ebx
mov    (%r12),%ebp
mov    %ebp,%edi
call   1110 <strerror@plt>
lea    0xc39(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xcce(%rip),%rdi
jmp    1434 <main+0x234>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%edx
mov    $0x72,%edi
mov    $0x400,%esi
call   10f0 <shmget@plt>
cmp    $0xffffffff,%eax
jne    1417 <main+0x217>
lea    0xc8b(%rip),%rdi
jmp    1434 <main+0x234>
mov    %eax,%r14d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <shmat@plt>
mov    %rax,%rbp
cmp    $0xffffffff,%ebp
jne    1443 <main+0x243>
lea    0xc5a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0x10(%rsp),%rbx
lea    0xbdc(%rip),%r15
lea    0xbc8(%rip),%r12
jmp    1470 <main+0x270>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     149d <main+0x29d>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1460 <main+0x260>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
jmp    1460 <main+0x260>
mov    %rbp,%rdi
call   1050 <shmdt@plt>
mov    0x2b24(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   10c0 <shmctl@plt>
test   %rax,%rax
jns    13d3 <main+0x1d3>
lea    0xb65(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.shmid_ds = type { i32 }
@IPC_CREAT = global i32 0
@.str = [14 x i8] c"shmget error\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Error: %d - %s\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"shmat error\0A\00"
@IPC_RMID = global i32 0
@.str.3 = [14 x i8] c"shmctl error\0A\00"
@.str.4 = [12 x i8] c"fork error\0A\00"
@.str.5 = [19 x i8] c"fork shmget error\0A\00"
@.str.6 = [19 x i8] c"fork: shmat error\0A\00"
@.str.7 = [13 x i8] c"fork: %s %s\0A\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [33 x i8] c"fork: close shared memroy error\0A\00"
@.str.10 = [17 x i8] c"this is a test.\0A\00"
@.str.11 = [15 x i8] c"Please input:\0A\00"
@.str.12 = [3 x i8] c"%s\00"
@.str.13 = [27 x i8] c"close shared memory error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.shmid_ds
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.shmid_ds
%9 = alloca [1024 x i8]
store i32 0, i32* %1
%10 = load i32, i32* @IPC_CREAT
%11 = or i32 %10, 511
%12 = call i32 @shmget(i32 114, i32 1024, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %0
%24 = load i32, i32* %2
%25 = call i64 @shmat(i32 %24, i32 0, i32 0)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %27 to i32
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %50
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %35)
%37 = load i32, i32* %2
%38 = load i32, i32* @IPC_RMID
%39 = call i64 @shmctl(i32 %37, i32 %38, %struct.shmid_ds* %4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %30
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %44, i8* %46)
br label %48
48: ; preds = %41, %30
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %23
%51 = call i64 (...) @fork()
store i64 %51, i64* %5
%52 = load i64, i64* %5
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = load i64, i64* %5
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %109
60: ; preds = %57
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = call i32 @memset(i8* %61, i32 0, i32 1024)
%63 = load i32, i32* @IPC_CREAT
%64 = call i32 @shmget(i32 114, i32 1024, i32 %63)
store i32 %64, i32* %6
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %60
%70 = load i32, i32* %6
%71 = call i64 @shmat(i32 %70, i32 0, i32 0)
%72 = inttoptr i64 %71 to i8*
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = ptrtoint i8* %73 to i32
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %69
br label %80
80: ; preds = %79, %97
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%82 = load i8*, i8** %7
%83 = call i64 @strcmp(i8* %81, i8* %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %80
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%87 = load i8*, i8** %7
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %86, i8* %87)
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%90 = load i8*, i8** %7
%91 = call i32 @strcpy(i8* %89, i8* %90)
br label %92
92: ; preds = %85, %80
%93 = load i8*, i8** %7
%94 = call i64 @strcmp(i8* %93, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %92
br label %98
97: ; preds = %92
br label %80
98: ; preds = %96
%99 = load i8*, i8** %7
%100 = call i32 @shmdt(i8* %99)
%101 = load i32, i32* %6
%102 = load i32, i32* @IPC_RMID
%103 = call i64 @shmctl(i32 %101, i32 %102, %struct.shmid_ds* %8)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %98
%106 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
br label %107
107: ; preds = %105, %98
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %57
%110 = load i8*, i8** %3
%111 = call i32 @strcpy(i8* %110, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %112
112: ; preds = %109, %126
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
%114 = load i8*, i8** %3
%115 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %120, %112
%117 = call signext i8 (...) @getchar()
%118 = sext i8 %117 to i32
%119 = icmp ne i32 %118, 10
br i1 %119, label %120, label %121
120: ; preds = %116
br label %116
121: ; preds = %116
%122 = load i8*, i8** %3
%123 = call i64 @strcmp(i8* %122, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%124 = icmp eq i64 %123, 0
br i1 %124, label %125, label %126
125: ; preds = %121
br label %127
126: ; preds = %121
br label %112
127: ; preds = %125
%128 = load i8*, i8** %3
%129 = call i32 @shmdt(i8* %128)
%130 = load i32, i32* %2
%131 = load i32, i32* @IPC_RMID
%132 = call i64 @shmctl(i32 %130, i32 %131, %struct.shmid_ds* %4)
%133 = icmp slt i64 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %127
%135 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0))
br label %136
136: ; preds = %134, %127
ret i32 0
}

LLVM IR (-O2):
%struct.shmid_ds = type { i32 }
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Error: %d - %s\0A\00"
@errno = global i32 0
@IPC_RMID = global i32 0
@.str.3 = [14 x i8] c"shmctl error\0A\00"
@.str.7 = [13 x i8] c"fork: %s %s\0A\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [33 x i8] c"fork: close shared memroy error\0A\00"
@.str.10 = [17 x i8] c"this is a test.\0A\00"
@.str.12 = [3 x i8] c"%s\00"
@.str.13 = [27 x i8] c"close shared memory error\0A\00"
@str = [14 x i8] c"Please input:\00"
@str.14 = [18 x i8] c"fork: shmat error\00"
@str.15 = [18 x i8] c"fork shmget error\00"
@str.16 = [11 x i8] c"fork error\00"
@str.17 = [12 x i8] c"shmat error\00"
@str.18 = [13 x i8] c"shmget error\00"
define i32 @main() {
%1 = alloca %struct.shmid_ds
%2 = alloca %struct.shmid_ds
%3 = alloca [1024 x i8]
%4 = bitcast %struct.shmid_ds* %1 to i8*
%5 = load i32, i32* @IPC_CREAT
%6 = or i32 %5, 511
%7 = tail call i32 @shmget(i32 114, i32 1024, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.18, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %12, i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = tail call i64 @shmat(i32 %7, i32 0, i32 0)
%18 = inttoptr i64 %17 to i8*
%19 = trunc i64 %17 to i32
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %38
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.17, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %25)
%27 = load i32, i32* @IPC_RMID
%28 = call i64 @shmctl(i32 %7, i32 %27, %struct.shmid_ds* %1)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %34)
br label %36
36: ; preds = %30, %21
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %16
%39 = tail call i64 (...) @fork()
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %38
%45 = icmp eq i64 %39, 0
br i1 %45, label %46, label %82
46: ; preds = %44
%47 = bitcast %struct.shmid_ds* %2 to i8*
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%49 = call i32 @memset(i8* %48, i32 0, i32 1024)
%50 = load i32, i32* @IPC_CREAT
%51 = call i32 @shmget(i32 114, i32 1024, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = call i64 @shmat(i32 %51, i32 0, i32 0)
%58 = inttoptr i64 %57 to i8*
%59 = trunc i64 %57 to i32
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.14, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %56, %70
%65 = call i64 @strcmp(i8* %48, i8* %58)
%66 = icmp eq i64 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %48, i8* %58)
%69 = call i32 @strcpy(i8* %48, i8* %58)
br label %70
70: ; preds = %67, %64
%71 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %64
73: ; preds = %70
%74 = call i32 @shmdt(i8* %58)
%75 = load i32, i32* @IPC_RMID
%76 = call i64 @shmctl(i32 %51, i32 %75, %struct.shmid_ds* %2)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %44
%83 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %84
84: ; preds = %90, %82
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%86 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* %18)
br label %87
87: ; preds = %87, %84
%88 = tail call signext i8 (...) @getchar()
%89 = icmp eq i8 %88, 10
br i1 %89, label %90, label %87
90: ; preds = %87
%91 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %84
93: ; preds = %90
%94 = tail call i32 @shmdt(i8* %18)
%95 = load i32, i32* @IPC_RMID
%96 = call i64 @shmctl(i32 %7, i32 %95, %struct.shmid_ds* %1)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %93
%99 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0))
br label %100
100: ; preds = %98, %93
ret i32 0
}