#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 /*<<< orphan*/ IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ msgctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int msgget(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int index;
  int msgid;
  for (index = 0; index < 10; ++index) {
    msgid = msgget(IPC_PRIVATE, IPC_CREAT);
    if (-1 == msgid) {
      perror("msgget error");
      exit(0);
    }
    printf("msgid = %d\n", msgid);
    msgctl(msgid, IPC_RMID, NULL);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11e4 <main+0x94>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1030 <msgget@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    11b2 <main+0x62>
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xa,%ebx
mov    0x2e81(%rip),%r15
mov    0x2e62(%rip),%r12
lea    0xe98(%rip),%r14
mov    0x2e5c(%rip),%r13
nopl   0x0(%rax)
mov    (%r15),%edi
mov    (%r12),%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     11b6 <main+0x66>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <msgctl@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x30>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [13 x i8] c"msgget error\00"
@.str.1 = [12 x i8] c"msgid = %d\0A\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i32, i32* @IPC_PRIVATE
%13 = load i32, i32* @IPC_CREAT
%14 = call i32 @msgget(i32 %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %11
%21 = load i32, i32* %7
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %7
%24 = load i32, i32* @IPC_RMID
%25 = call i32 @msgctl(i32 %23, i32 %24, i32* null)
br label %26
26: ; preds = %20
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %8
29: ; preds = %8
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [13 x i8] c"msgget error\00"
@.str.1 = [12 x i8] c"msgid = %d\0A\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %12
%4 = phi i32 [ 0, %2 ], [ %16, %12 ]
%5 = load i32, i32* @IPC_PRIVATE
%6 = load i32, i32* @IPC_CREAT
%7 = tail call i32 @msgget(i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%14 = load i32, i32* @IPC_RMID
%15 = tail call i32 @msgctl(i32 %7, i32 %14, i32* null)
%16 = add nuw nsw i32 %4, 1
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %3
18: ; preds = %12
%19 = tail call i32 @exit(i32 0)
unreachable
}