#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 ipc_perm {
  int __seq;
};
struct msqid_ds {
  struct ipc_perm msg_perm;
};

/* Variables and functions */
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int msgget(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int i, msgid;
  struct msqid_ds ds;
  struct ipc_perm *perm;
  for (i = 0; i < 10; i++) {
    msgid = msgget(IPC_PRIVATE, 0);
    printf("the msgid=%d", msgid);
    msgctl(msgid, IPC_STAT, &ds);
    perm = &(ds.msg_perm);
    printf("  __seq=%d\n", perm->__seq);
    msgctl(msgid, IPC_RMID, 0);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11db <main+0x9b>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <msgget@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <msgctl@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2e0e(%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    115d <main+0x1d>
xor    %edi,%edi
call   1060 <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),%r13
mov    %rsp,%r15
lea    0xeac(%rip),%r12
mov    0x2e68(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <msgget@plt>
mov    %eax,%ebp
lea    0xe77(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1050 <msgctl@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
mov    (%r14),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <msgctl@plt>
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.msqid_ds = type { %struct.ipc_perm }
%struct.ipc_perm = type { i32 }
@IPC_PRIVATE = global i32 0
@.str = [13 x i8] c"the msgid=%d\00"
@IPC_STAT = global i32 0
@.str.1 = [12 x i8] c" __seq=%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
%8 = alloca %struct.msqid_ds
%9 = alloca %struct.ipc_perm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = load i32, i32* @IPC_PRIVATE
%15 = call i32 @msgget(i32 %14, i32 0)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %7
%19 = load i32, i32* @IPC_STAT
%20 = call i32 @msgctl(i32 %18, i32 %19, %struct.msqid_ds* %8)
%21 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %8, i32 0, i32 0
store %struct.ipc_perm* %21, %struct.ipc_perm** %9
%22 = load %struct.ipc_perm*, %struct.ipc_perm** %9
%23 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %7
%27 = load i32, i32* @IPC_RMID
%28 = call i32 @msgctl(i32 %26, i32 %27, %struct.msqid_ds* null)
br label %29
29: ; preds = %13
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %10
32: ; preds = %10
%33 = call i32 @exit(i32 0)
unreachable
}

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