#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*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void Print_paths(int pred[], int n) {
  int v, w, *path, count, i;
  path = malloc(n * sizeof(int));
  printf("  v     Path 0->v\n");
  printf("----    ---------\n");
  for (v = 1; v < n; v++) {
    printf("%3d:    ", v);
    count = 0;
    w = v;
    while (w != 0) {
      path[count] = w;
      count++;
      w = pred[w];
    }
    printf("0 ");
    for (i = count - 1; i >= 0; i--)
      printf("%d ", path[i]);
    printf("\n");
  }
  free(path);
}


x86 assembly (clang, -O0):
<Print_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1237 <Print_paths+0x107>
mov    -0x10(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d3 <Print_paths+0xa3>
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
jmp    119f <Print_paths+0x6f>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     121b <Print_paths+0xeb>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11ea <Print_paths+0xba>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1175 <Print_paths+0x45>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Print_paths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x0(,%rbp,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe97(%rip),%rdi
call   1050 <puts@plt>
lea    0xe9d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,0x10(%rsp)
cmp    $0x2,%ebp
jl     1255 <Print_paths+0x105>
mov    $0x1,%ebp
lea    0xe68(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe49(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffffffffffff,%rax
xor    %edx,%edx
mov    $0x1,%esi
mov    %ebp,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %esi,%r13d
mov    %edx,%r14d
mov    %ebp,0x4(%rbx,%rax,4)
movslq %ebp,%rcx
mov    (%r15,%rcx,4),%ebp
add    $0x1,%rax
lea    0x1(%r13),%esi
lea    0x1(%r14),%edx
test   %ebp,%ebp
jne    11e0 <Print_paths+0x90>
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%eax
lea    (%rbx,%rax,4),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%r13d
add    $0xfffffffffffffffc,%rbp
test   %r13d,%r13d
jg     1220 <Print_paths+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%ebp
add    $0x1,%ebp
cmp    0x10(%rsp),%ebp
jne    11b0 <Print_paths+0x60>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str.2 = [9 x i8] c"%3d: \00"
@.str.3 = [3 x i8] c"0 \00"
@.str.4 = [4 x i8] c"%d \00"
@str = [18 x i8] c" v Path 0->v\00"
@str.6 = [18 x i8] c"---- ---------\00"
define void @Print_paths(i32* nocapture %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i32* @malloc(i32 %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%7 = icmp sgt i32 %1, 1
br i1 %7, label %8, label %35
8: ; preds = %2, %31
%9 = phi i32 [ %33, %31 ], [ 1, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %15, %11 ]
%13 = phi i32 [ %9, %8 ], [ %18, %11 ]
%14 = getelementptr inbounds i32, i32* %4, i64 %12
store i32 %13, i32* %14
%15 = add nuw i64 %12, 1
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = and i64 %12, 4294967295
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ %22, %20 ], [ %28, %23 ]
%25 = getelementptr inbounds i32, i32* %4, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = add nsw i64 %24, -1
%29 = trunc i64 %24 to i32
%30 = icmp sgt i32 %29, 0
br i1 %30, label %23, label %31
31: ; preds = %23
%32 = tail call i32 @putchar(i32 10)
%33 = add nuw nsw i32 %9, 1
%34 = icmp eq i32 %33, %1
br i1 %34, label %35, label %8
35: ; preds = %31, %2
%36 = tail call i32 @free(i32* %4)
ret void
}