#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*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ key_t;
typedef int /*<<< orphan*/ int8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int S_IFREG;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ftok(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ msgctl(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ msgget(int /*<<< orphan*/, int);
int msgrcv(int /*<<< orphan*/, struct msgbuf_s *, int, int, int /*<<< orphan*/);
int msgsnd(int /*<<< orphan*/, struct msgbuf_s *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unlink(char *);
int8_t create_children(int32_t number) {
  unlink("/tmp/ipcmsg");
  mknod("/tmp/ipcmsg", S_IFREG | 0666, 0);
  key_t key_ipc = ftok("/tmp/ipcmsg", getpid());
  uint32_t id = msgget(key_ipc, IPC_CREAT | 0666);
  msgctl(id, IPC_RMID, NULL);
  id = msgget(key_ipc, IPC_CREAT | 0666);
  typedef struct msgbuf_s {
    long mtype;
    uint64_t c_number;
  } msgbuf_t;
  msgbuf_t msgbuf;
  int DataLength = sizeof(msgbuf_t) - sizeof(msgbuf.mtype);
  int i = 0;
  for (i = 1; i <= number; i++) {
    int childpid = fork();
    if (childpid == 0) {
      if (msgrcv(id, &msgbuf, DataLength, i, 0) == -1)
        exit(EXIT_FAILURE);
      fprintf(stdout, "%d\n", i);
      fflush(stdout);
      msgbuf.mtype = i + 1;
      if (msgsnd(id, &msgbuf, DataLength, 0) == -1)
        exit(EXIT_FAILURE);
      exit(EXIT_SUCCESS);
    }
    if (childpid == -1) {
      perror("");
      msgctl(id, IPC_RMID, NULL);
      exit(EXIT_FAILURE);
    }
  }
  msgbuf.mtype = 1;
  msgsnd(id, &msgbuf, DataLength, 0);
  msgrcv(id, &msgbuf, DataLength, number + 1, 0);
  msgctl(id, IPC_RMID, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<create_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe1e(%rip),%rdi
call   1040 <unlink@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe03(%rip),%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%esi
lea    0xdec(%rip),%rdi
call   10d0 <ftok@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <msgctl@plt>
mov    -0x8(%rbp),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0xc(%rbp)
movl   $0x8,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     137a <create_children+0x1aa>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    132e <create_children+0x15e>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %r8d,%r8d
call   10e0 <msgrcv@plt>
cmp    $0xffffffff,%eax
jne    12c6 <create_children+0xf6>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xd33(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   1060 <msgsnd@plt>
cmp    $0xffffffff,%eax
jne    1320 <create_children+0x150>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1367 <create_children+0x197>
lea    0xcd0(%rip),%rdi
call   10b0 <perror@plt>
mov    -0xc(%rbp),%edi
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <msgctl@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    136c <create_children+0x19c>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    127a <create_children+0xaa>
movq   $0x1,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
xor    %ecx,%ecx
call   1060 <msgsnd@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
xor    %r8d,%r8d
call   10e0 <msgrcv@plt>
mov    -0xc(%rbp),%edi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <msgctl@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_children>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0xe1a(%rip),%rbp
mov    %rbp,%rdi
call   1040 <unlink@plt>
mov    0x2df3(%rip),%rax
mov    $0x1b6,%ebx
mov    (%rax),%esi
or     %ebx,%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10d0 <ftok@plt>
mov    %eax,%ebp
mov    0x2d96(%rip),%r12
mov    (%r12),%esi
or     %ebx,%esi
mov    %eax,%edi
call   1030 <msgget@plt>
mov    0x2d9a(%rip),%r15
mov    (%r15),%esi
mov    %eax,%edi
xor    %edx,%edx
call   10a0 <msgctl@plt>
or     (%r12),%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <msgget@plt>
mov    %eax,%r12d
test   %r14d,%r14d
jle    128c <create_children+0xbc>
mov    %r14d,%ebx
neg    %ebx
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     12df <create_children+0x10f>
test   %eax,%eax
je     12fa <create_children+0x12a>
add    $0x1,%rbp
lea    (%rbx,%rbp,1),%eax
cmp    $0x2,%eax
jne    1270 <create_children+0xa0>
add    $0x1,%r14d
movq   $0x1,(%rsp)
mov    %rsp,%rbp
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1060 <msgsnd@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
mov    %r14d,%ecx
xor    %r8d,%r8d
call   10e0 <msgrcv@plt>
mov    (%r15),%esi
mov    %r12d,%edi
xor    %edx,%edx
call   10a0 <msgctl@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd29(%rip),%rdi
call   10b0 <perror@plt>
mov    (%r15),%esi
mov    %r12d,%edi
xor    %edx,%edx
call   10a0 <msgctl@plt>
jmp    1353 <create_children+0x183>
lea    -0x1(%rbp),%r14
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
mov    %r14d,%ecx
xor    %r8d,%r8d
call   10e0 <msgrcv@plt>
cmp    $0xffffffff,%eax
je     1353 <create_children+0x183>
mov    0x2ca8(%rip),%rbx
mov    (%rbx),%edi
lea    0xce3(%rip),%rsi
mov    %r14d,%edx
call   1070 <fprintf@plt>
mov    (%rbx),%edi
call   1090 <fflush@plt>
mov    %rbp,(%rsp)
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1060 <msgsnd@plt>
cmp    $0xffffffff,%eax
jne    1361 <create_children+0x191>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.msgbuf_s = type { i64, i32 }
%struct.msgbuf_s.0 = type opaque
%struct.msgbuf_s.1 = type opaque
@.str = [12 x i8] c"/tmp/ipcmsg\00"
@S_IFREG = global i32 0
@IPC_CREAT = global i32 0
@IPC_RMID = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [1 x i8] zeroinitializer
define i32 @create_children(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.msgbuf_s
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @S_IFREG
%11 = or i32 %10, 438
%12 = call i32 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11, i32 0)
%13 = call i32 (...) @getpid()
%14 = call i32 @ftok(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = load i32, i32* @IPC_CREAT
%17 = or i32 %16, 438
%18 = call i32 @msgget(i32 %15, i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = load i32, i32* @IPC_RMID
%21 = call i32 @msgctl(i32 %19, i32 %20, i32* null)
%22 = load i32, i32* %3
%23 = load i32, i32* @IPC_CREAT
%24 = or i32 %23, 438
%25 = call i32 @msgget(i32 %22, i32 %24)
store i32 %25, i32* %4
store i32 8, i32* %6
store i32 0, i32* %7
store i32 1, i32* %7
br label %26
26: ; preds = %76, %1
%27 = load i32, i32* %7
%28 = load i32, i32* %2
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %79
30: ; preds = %26
%31 = call i32 (...) @fork()
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %65
34: ; preds = %30
%35 = load i32, i32* %4
%36 = bitcast %struct.msgbuf_s* %5 to %struct.msgbuf_s.0*
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = call i32 @msgrcv(i32 %35, %struct.msgbuf_s.0* %36, i32 %37, i32 %38, i32 0)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %34
%45 = load i32, i32* @stdout
%46 = load i32, i32* %7
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds %struct.msgbuf_s, %struct.msgbuf_s* %5, i32 0, i32 0
store i64 %52, i64* %53
%54 = load i32, i32* %4
%55 = bitcast %struct.msgbuf_s* %5 to %struct.msgbuf_s.1*
%56 = load i32, i32* %6
%57 = call i32 @msgsnd(i32 %54, %struct.msgbuf_s.1* %55, i32 %56, i32 0)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %44
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %44
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %30
%66 = load i32, i32* %8
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%70 = load i32, i32* %4
%71 = load i32, i32* @IPC_RMID
%72 = call i32 @msgctl(i32 %70, i32 %71, i32* null)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %65
br label %76
76: ; preds = %75
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %26
79: ; preds = %26
%80 = getelementptr inbounds %struct.msgbuf_s, %struct.msgbuf_s* %5, i32 0, i32 0
store i64 1, i64* %80
%81 = load i32, i32* %4
%82 = bitcast %struct.msgbuf_s* %5 to %struct.msgbuf_s.1*
%83 = load i32, i32* %6
%84 = call i32 @msgsnd(i32 %81, %struct.msgbuf_s.1* %82, i32 %83, i32 0)
%85 = load i32, i32* %4
%86 = bitcast %struct.msgbuf_s* %5 to %struct.msgbuf_s.0*
%87 = load i32, i32* %6
%88 = load i32, i32* %2
%89 = add nsw i32 %88, 1
%90 = call i32 @msgrcv(i32 %85, %struct.msgbuf_s.0* %86, i32 %87, i32 %89, i32 0)
%91 = load i32, i32* %4
%92 = load i32, i32* @IPC_RMID
%93 = call i32 @msgctl(i32 %91, i32 %92, i32* null)
ret i32 0
}

LLVM IR (-O2):
%struct.msgbuf_s = type { i64, i32 }
%struct.msgbuf_s.0 = type opaque
%struct.msgbuf_s.1 = type opaque
@.str = [12 x i8] c"/tmp/ipcmsg\00"
@S_IFREG = global i32 0
@IPC_CREAT = global i32 0
@IPC_RMID = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [1 x i8] zeroinitializer
define i32 @create_children(i32 %0) {
%2 = alloca %struct.msgbuf_s
%3 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @S_IFREG
%5 = or i32 %4, 438
%6 = tail call i32 @mknod(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 0)
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @ftok(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 %9, 438
%11 = tail call i32 @msgget(i32 %8, i32 %10)
%12 = load i32, i32* @IPC_RMID
%13 = tail call i32 @msgctl(i32 %11, i32 %12, i32* null)
%14 = load i32, i32* @IPC_CREAT
%15 = or i32 %14, 438
%16 = tail call i32 @msgget(i32 %8, i32 %15)
%17 = bitcast %struct.msgbuf_s* %2 to i8*
%18 = icmp slt i32 %0, 1
br i1 %18, label %55, label %19
19: ; preds = %1, %52
%20 = phi i32 [ %53, %52 ], [ 1, %1 ]
%21 = tail call i32 (...) @fork()
switch i32 %21, label %52 [
i32 0, label %22
i32 -1, label %46
]
22: ; preds = %19
%23 = bitcast %struct.msgbuf_s* %2 to %struct.msgbuf_s.0*
%24 = call i32 @msgrcv(i32 %16, %struct.msgbuf_s.0* %23, i32 8, i32 %20, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = load i32, i32* @stdout
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = add nuw nsw i32 %20, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds %struct.msgbuf_s, %struct.msgbuf_s* %2, i64 0, i32 0
store i64 %35, i64* %36
%37 = bitcast %struct.msgbuf_s* %2 to %struct.msgbuf_s.1*
%38 = call i32 @msgsnd(i32 %16, %struct.msgbuf_s.1* %37, i32 8, i32 0)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %29
%44 = load i32, i32* @EXIT_SUCCESS
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %19
%47 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* @IPC_RMID
%49 = tail call i32 @msgctl(i32 %16, i32 %48, i32* null)
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %19
%53 = add nuw i32 %20, 1
%54 = icmp eq i32 %20, %0
br i1 %54, label %55, label %19
55: ; preds = %52, %1
%56 = add i32 %0, 1
%57 = getelementptr inbounds %struct.msgbuf_s, %struct.msgbuf_s* %2, i64 0, i32 0
store i64 1, i64* %57
%58 = bitcast %struct.msgbuf_s* %2 to %struct.msgbuf_s.1*
%59 = call i32 @msgsnd(i32 %16, %struct.msgbuf_s.1* %58, i32 8, i32 0)
%60 = bitcast %struct.msgbuf_s* %2 to %struct.msgbuf_s.0*
%61 = call i32 @msgrcv(i32 %16, %struct.msgbuf_s.0* %60, i32 8, i32 %56, i32 0)
%62 = load i32, i32* @IPC_RMID
%63 = call i32 @msgctl(i32 %16, i32 %62, i32* null)
ret i32 0
}