#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 *findOrder(int, int **, int, int *, int *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i, course_num = 3, pair_num = 1;
  int **pairs = malloc(pair_num * sizeof(int *));
  int *col_sizes = malloc(pair_num * sizeof(int));
  pairs[0] = malloc(2 * sizeof(int));
  pairs[0][0] = 1;
  pairs[0][1] = 0;
  int count = 0;
  int *ids = findOrder(course_num, pairs, pair_num, col_sizes, &count);
  for (i = 0; i < count; i++) {
    printf("%d ", ids[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movl   $0x0,0x4(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1050 <findOrder@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fe <main+0xce>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11cb <main+0x9b>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
movq   $0x1,(%rax)
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r8
mov    $0x3,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <findOrder@plt>
cmpl   $0x0,0xc(%rsp)
jle    11cc <main+0x8c>
mov    %rax,%r15
lea    0xe56(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11b0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %1
store i32 3, i32* %3
store i32 1, i32* %4
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
%14 = bitcast i8* %13 to i32**
store i32** %14, i32*** %5
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
%20 = bitcast i8* %19 to i32*
store i32* %20, i32** %6
%21 = call i8* @malloc(i32 8)
%22 = bitcast i8* %21 to i32*
%23 = load i32**, i32*** %5
%24 = getelementptr inbounds i32*, i32** %23, i64 0
store i32* %22, i32** %24
%25 = load i32**, i32*** %5
%26 = getelementptr inbounds i32*, i32** %25, i64 0
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32 1, i32* %28
%29 = load i32**, i32*** %5
%30 = getelementptr inbounds i32*, i32** %29, i64 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32 0, i32* %32
store i32 0, i32* %7
%33 = load i32, i32* %3
%34 = load i32**, i32*** %5
%35 = load i32, i32* %4
%36 = load i32*, i32** %6
%37 = call i32* @findOrder(i32 %33, i32** %34, i32 %35, i32* %36, i32* %7)
store i32* %37, i32** %8
store i32 0, i32* %2
br label %38
38: ; preds = %49, %0
%39 = load i32, i32* %2
%40 = load i32, i32* %7
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32*, i32** %8
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %38
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%3 = bitcast i8* %2 to i32**
%4 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%5 = bitcast i8* %4 to i32*
%6 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%7 = bitcast i8* %6 to i32*
%8 = bitcast i8* %2 to i8**
store i8* %6, i8** %8
store i32 1, i32* %7
%9 = getelementptr inbounds i32, i32* %7, i64 1
store i32 0, i32* %9
%10 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%11 = call i32* @findOrder(i32 3, i32** %3, i32 1, i32* %5, i32* %1)
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %0, %14
%15 = phi i64 [ %19, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds i32, i32* %11, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %15, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %14, label %23
23: ; preds = %14, %0
%24 = call i32 @putchar(i32 10)
ret i32 0
}