#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*/ IPC_RMID;
int /*<<< orphan*/ msgctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int msgget(int, int);
int /*<<< orphan*/ msgrcv(int, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int main() {
  int id = msgget(0x8888, 0644 | IPC_CREAT);
  if (id == -1) {
    perror("msgget");
    return 1;
  }
  char buf[128];
  msgrcv(id, buf, sizeof(buf), 0, 0);
  printf("第一条:");
  puts(buf);
  msgrcv(id, buf, sizeof(buf), 0, 0);
  printf("第二条:");
  puts(buf);
  msgctl(id, IPC_RMID, NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
or     $0x1a4,%esi
mov    $0x8888,%edi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b0 <main+0x50>
lea    0xe61(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1080 <msgrcv@plt>
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1080 <msgrcv@plt>
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <msgctl@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e66(%rip),%rax
mov    $0x1a4,%esi
or     (%rax),%esi
mov    $0x8888,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1201 <main+0xa1>
mov    %eax,%ebp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <msgrcv@plt>
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <msgrcv@plt>
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <msgctl@plt>
mov    %r14d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf8(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%r14d
jmp    11f2 <main+0x92>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"msgget\00"
@.str.1 = [11 x i8] c"\E7\AC\AC\E4\B8\80\E6\9D\A1:\00"
@.str.2 = [11 x i8] c"\E7\AC\AC\E4\BA\8C\E6\9D\A1:\00"
@IPC_RMID = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 420, %4
%6 = call i32 @msgget(i32 34952, i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %27
11: ; preds = %0
%12 = load i32, i32* %2
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%14 = call i32 @msgrcv(i32 %12, i8* %13, i32 128, i32 0, i32 0)
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%17 = call i32 @puts(i8* %16)
%18 = load i32, i32* %2
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @msgrcv(i32 %18, i8* %19, i32 128, i32 0, i32 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%23 = call i32 @puts(i8* %22)
%24 = load i32, i32* %2
%25 = load i32, i32* @IPC_RMID
%26 = call i32 @msgctl(i32 %24, i32 %25, i32* null)
br label %27
27: ; preds = %11, %9
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"msgget\00"
@.str.1 = [11 x i8] c"\E7\AC\AC\E4\B8\80\E6\9D\A1:\00"
@.str.2 = [11 x i8] c"\E7\AC\AC\E4\BA\8C\E6\9D\A1:\00"
@IPC_RMID = global i32 0
define i32 @main() {
%1 = alloca [128 x i8]
%2 = load i32, i32* @IPC_CREAT
%3 = or i32 %2, 420
%4 = tail call i32 @msgget(i32 34952, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = call i32 @msgrcv(i32 %4, i8* %9, i32 128, i32 0, i32 0)
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @puts(i8* %9)
%13 = call i32 @msgrcv(i32 %4, i8* %9, i32 128, i32 0, i32 0)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @puts(i8* %9)
%16 = load i32, i32* @IPC_RMID
%17 = call i32 @msgctl(i32 %4, i32 %16, i32* null)
br label %18
18: ; preds = %8, %6
%19 = phi i32 [ 1, %6 ], [ 0, %8 ]
ret i32 %19
}