#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int **create_pipes(int num_pipes) {
  int **pipes = (int **)malloc(sizeof(int **) * num_pipes);
  int index = 0;
  for (; index < num_pipes; index++) {
    pipes[index] = (int *)malloc(sizeof(int *) * 2);
    if (pipe(pipes[index]) == -1) {
      perror("Create pipes: Pipe not successful");
      return 0;
    }
  }
  return pipes;
}


x86 assembly (clang, -O0):
<create_pipes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c0 <create_pipes+0x90>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11ad <create_pipes+0x7d>
lea    0xe65(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <create_pipes+0x98>
jmp    11b2 <create_pipes+0x82>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <create_pipes+0x25>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_pipes>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1184 <create_pipes+0x54>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    %rax,%rdi
call   1030 <pipe@plt>
cmp    $0xffffffff,%eax
je     118d <create_pipes+0x5d>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <create_pipes+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6c(%rip),%rdi
call   1050 <perror@plt>
xor    %r15d,%r15d
jmp    1184 <create_pipes+0x54>

LLVM IR (-O0):
@.str = [34 x i8] c"Create pipes: Pipe not successful\00"
define i32** @create_pipes(i32 %0) {
%2 = alloca i32**
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32**
store i32** %11, i32*** %4
store i32 0, i32* %5
br label %12
12: ; preds = %33, %1
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = call i64 @malloc(i32 16)
%18 = inttoptr i64 %17 to i32*
%19 = load i32**, i32*** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
store i32* %18, i32** %22
%23 = load i32**, i32*** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
%27 = load i32*, i32** %26
%28 = call i32 @pipe(i32* %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %16
%31 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32** null, i32*** %2
br label %38
32: ; preds = %16
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %12
36: ; preds = %12
%37 = load i32**, i32*** %4
store i32** %37, i32*** %2
br label %38
38: ; preds = %36, %30
%39 = load i32**, i32*** %2
ret i32** %39
}

LLVM IR (-O2):
@.str = [34 x i8] c"Create pipes: Pipe not successful\00"
define i32** @create_pipes(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32**
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = zext i32 %0 to i64
br label %10
8: ; preds = %10
%9 = icmp eq i64 %17, %7
br i1 %9, label %20, label %10
10: ; preds = %6, %8
%11 = phi i64 [ 0, %6 ], [ %17, %8 ]
%12 = tail call i64 @malloc(i32 16)
%13 = inttoptr i64 %12 to i32*
%14 = getelementptr inbounds i32*, i32** %4, i64 %11
store i32* %13, i32** %14
%15 = tail call i32 @pipe(i32* %13)
%16 = icmp eq i32 %15, -1
%17 = add nuw nsw i64 %11, 1
br i1 %16, label %18, label %8
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %8, %1, %18
%21 = phi i32** [ null, %18 ], [ %4, %1 ], [ %4, %8 ]
ret i32** %21
}