#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 */
char *malloc(int);
char *shm_create_by_monitor(int);
char **shm_create(int variant_count, int *child) {
  int i;
  char *memory_segments[variant_count];
  for (i = 0; i < variant_count; i++)
    memory_segments[i] = malloc(1 * sizeof(char *));
  for (i = 0; i < variant_count; i++)
    memory_segments[i] = shm_create_by_monitor(child[i]);
  return memory_segments;
}


x86 assembly (clang, -O0):
<shm_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1190 <shm_create+0x70>
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <shm_create+0x3d>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d0 <shm_create+0xb0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <shm_create_by_monitor@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <shm_create+0x77>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_create>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
mov    %rsp,%r13
lea    0xf(,%r12,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %edi,%edi
jle    1197 <shm_create+0x77>
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <shm_create+0x40>
test   %r15d,%r15d
jle    1197 <shm_create+0x77>
xor    %ebx,%ebx
nop
mov    (%r14,%rbx,4),%edi
call   1040 <shm_create_by_monitor@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <shm_create+0x60>
mov    %r13,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @shm_create(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %6
%11 = alloca i8*, i64 %9
store i64 %9, i64* %7
store i32 0, i32* %5
br label %12
12: ; preds = %21, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = call i8* @malloc(i32 8)
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %11, i64 %19
store i8* %17, i8** %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
store i32 0, i32* %5
br label %25
25: ; preds = %39, %24
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load i32*, i32** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i8* @shm_create_by_monitor(i32 %34)
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %11, i64 %37
store i8* %35, i8** %38
br label %39
39: ; preds = %29
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %25
42: ; preds = %25
%43 = load i8*, i8** %6
ret i8** %11
}

LLVM IR (-O2):
define noalias i8** @shm_create(i32 %0, i32* nocapture %1) {
%3 = zext i32 %0 to i64
%4 = alloca i8*, i64 %3
%5 = icmp sgt i32 %0, 0
br i1 %5, label %7, label %21
6: ; preds = %7
br i1 %5, label %13, label %21
7: ; preds = %2, %7
%8 = phi i64 [ %11, %7 ], [ 0, %2 ]
%9 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%10 = getelementptr inbounds i8*, i8** %4, i64 %8
store i8* %9, i8** %10
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, %3
br i1 %12, label %6, label %7
13: ; preds = %6, %13
%14 = phi i64 [ %19, %13 ], [ 0, %6 ]
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = load i32, i32* %15
%17 = tail call i8* @shm_create_by_monitor(i32 %16)
%18 = getelementptr inbounds i8*, i8** %4, i64 %14
store i8* %17, i8** %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %3
br i1 %20, label %21, label %13
21: ; preds = %13, %2, %6
ret i8** %4
}