#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(int *);
int *malloc(int);
void Print_paths(int pred[], int n, FILE *fp) {
  int v, w, *path, count, i;
  path = malloc(n * sizeof(int));
  fprintf(fp, "  v     Path 0->v\n");
  fprintf(fp, "----    ---------\n");
  for (v = 1; v < n; v++) {
    fprintf(fp, "%3d:    ", v);
    count = 0;
    w = v;
    while (w != 0) {
      path[count] = w;
      count++;
      w = pred[w];
    }
    fprintf(fp, "0 ");
    for (i = count - 1; i >= 0; i--)
      fprintf(fp, "%d ", path[i]);
    fprintf(fp, "\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)
mov    %rdx,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1253 <Print_paths+0x123>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11e3 <Print_paths+0xb3>
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
jmp    11af <Print_paths+0x7f>
mov    -0x18(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     1233 <Print_paths+0x103>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    11fe <Print_paths+0xce>
mov    -0x18(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <Print_paths+0x51>
mov    -0x28(%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    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x0(,%rbp,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xe84(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe7e(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbp,0x10(%rsp)
cmp    $0x2,%ebp
jl     127b <Print_paths+0x12b>
mov    $0x1,%ebp
lea    0xe71(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe4c(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffffffffffff,%rax
xor    %edx,%edx
mov    $0x1,%esi
mov    %ebp,0xc(%rsp)
mov    %ebp,%ecx
nopw   0x0(%rax,%rax,1)
mov    %esi,%r14d
mov    %edx,%ebp
mov    %ecx,0x4(%r12,%rax,4)
movslq %ecx,%rcx
mov    (%r15,%rcx,4),%ecx
add    $0x1,%rax
lea    0x1(%r14),%esi
lea    0x1(%rbp),%edx
test   %ecx,%ecx
jne    1200 <Print_paths+0xb0>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdfe(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %ebp,%eax
lea    (%r12,%rax,4),%rbp
nop
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xffffffff,%r14d
add    $0xfffffffffffffffc,%rbp
test   %r14d,%r14d
jg     1240 <Print_paths+0xf0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0xc(%rsp),%ebp
add    $0x1,%ebp
cmp    0x10(%rsp),%ebp
jne    11d0 <Print_paths+0x80>
mov    %r12,%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, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %9
%17 = load i32*, i32** %6
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %6
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %21
21: ; preds = %68, %3
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %71
25: ; preds = %21
%26 = load i32*, i32** %6
%27 = load i32, i32* %7
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 0, i32* %10
%29 = load i32, i32* %7
store i32 %29, i32* %8
br label %30
30: ; preds = %33, %25
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32, i32* %8
%35 = load i32*, i32** %9
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
%41 = load i32*, i32** %4
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %8
br label %30
46: ; preds = %30
%47 = load i32*, i32** %6
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* %10
%50 = sub nsw i32 %49, 1
store i32 %50, i32* %11
br label %51
51: ; preds = %62, %46
%52 = load i32, i32* %11
%53 = icmp sge i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %51
%55 = load i32*, i32** %6
%56 = load i32*, i32** %9
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %54
%63 = load i32, i32* %11
%64 = add nsw i32 %63, -1
store i32 %64, i32* %11
br label %51
65: ; preds = %51
%66 = load i32*, i32** %6
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %65
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %21
71: ; preds = %21
%72 = load i32*, i32** %9
%73 = call i32 @free(i32* %72)
ret void
}

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