#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ msg_rcv(int, int);
int /*<<< orphan*/ msg_snd(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
void parent(int msqid) {
  int i = 1;
  for (i = 1; i < 32000; i += 2) {
    printf("Server: %d\n", i);
    fflush(stdout);
    msg_snd(msqid, i);
    msg_rcv(msqid, i + 1);
    sleep(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x7d00,-0x8(%rbp)
jge    11d4 <parent+0x74>
mov    -0x8(%rbp),%esi
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <msg_snd@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1030 <msg_rcv@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1179 <parent+0x19>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<parent>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x1,%ebx
lea    0xe8b(%rip),%r14
mov    0x2e64(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <msg_snd@plt>
lea    0x1(%rbx),%esi
mov    %ebp,%edi
call   1030 <msg_rcv@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0x2(%rbx),%eax
cmp    $0x7cfe,%ebx
mov    %eax,%ebx
jb     1180 <parent+0x20>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Server: %d\0A\00"
@stdout = global i32 0
define void @parent(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
store i32 1, i32* %3
br label %4
4: ; preds = %20, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 32000
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @msg_snd(i32 %12, i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
%18 = call i32 @msg_rcv(i32 %15, i32 %17)
%19 = call i32 @sleep(i32 1)
br label %20
20: ; preds = %7
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 2
store i32 %22, i32* %3
br label %4
23: ; preds = %4
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"Server: %d\0A\00"
@stdout = global i32 0
define void @parent(i32 %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 1, %1 ], [ %11, %2 ]
%4 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = tail call i32 @msg_snd(i32 %0, i32 %3)
%8 = add nuw nsw i32 %3, 1
%9 = tail call i32 @msg_rcv(i32 %0, i32 %8)
%10 = tail call i32 @sleep(i32 1)
%11 = add nuw nsw i32 %3, 2
%12 = icmp ult i32 %3, 31998
br i1 %12, label %2, label %13
13: ; preds = %2
%14 = tail call i32 @exit(i32 0)
unreachable
}