#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 */
struct graph {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_edge(struct graph *, int, int);
struct graph *create_graph(int);
scalar_t__ detect_cycle(struct graph *);
int /*<<< orphan*/ printf(char *);
void main() {
  struct graph *G = create_graph(5);
  add_edge(G, 1, 3);
  add_edge(G, 1, 5);
  add_edge(G, 2, 3);
  add_edge(G, 4, 5);
  add_edge(G, 5, 2);
  add_edge(G, 2, 1);
  if (detect_cycle(G)) {
    printf("Cycle present");
  } else {
    printf("Cycle not present");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x5,%edi
call   1050 <create_graph@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x3,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <add_edge@plt>
mov    -0x8(%rbp),%rdi
call   1060 <detect_cycle@plt>
cmp    $0x0,%rax
je     11ec <main+0xac>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    11f8 <main+0xb8>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x5,%edi
call   1050 <create_graph@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x3,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <add_edge@plt>
mov    %rbx,%rdi
call   1060 <detect_cycle@plt>
test   %rax,%rax
lea    0xe42(%rip),%rax
lea    0xe2d(%rip),%rdi
cmove  %rax,%rdi
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.graph = type { i32 }
@.str = [14 x i8] c"Cycle present\00"
@.str.1 = [18 x i8] c"Cycle not present\00"
define void @main() {
%1 = alloca %struct.graph*
%2 = call %struct.graph* @create_graph(i32 5)
store %struct.graph* %2, %struct.graph** %1
%3 = load %struct.graph*, %struct.graph** %1
%4 = call i32 @add_edge(%struct.graph* %3, i32 1, i32 3)
%5 = load %struct.graph*, %struct.graph** %1
%6 = call i32 @add_edge(%struct.graph* %5, i32 1, i32 5)
%7 = load %struct.graph*, %struct.graph** %1
%8 = call i32 @add_edge(%struct.graph* %7, i32 2, i32 3)
%9 = load %struct.graph*, %struct.graph** %1
%10 = call i32 @add_edge(%struct.graph* %9, i32 4, i32 5)
%11 = load %struct.graph*, %struct.graph** %1
%12 = call i32 @add_edge(%struct.graph* %11, i32 5, i32 2)
%13 = load %struct.graph*, %struct.graph** %1
%14 = call i32 @add_edge(%struct.graph* %13, i32 2, i32 1)
%15 = load %struct.graph*, %struct.graph** %1
%16 = call i64 @detect_cycle(%struct.graph* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
20: ; preds = %0
%21 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
ret void
}

LLVM IR (-O2):
%struct.graph = type { i32 }
@.str = [14 x i8] c"Cycle present\00"
@.str.1 = [18 x i8] c"Cycle not present\00"
define void @main() {
%1 = tail call %struct.graph* @create_graph(i32 5)
%2 = tail call i32 @add_edge(%struct.graph* %1, i32 1, i32 3)
%3 = tail call i32 @add_edge(%struct.graph* %1, i32 1, i32 5)
%4 = tail call i32 @add_edge(%struct.graph* %1, i32 2, i32 3)
%5 = tail call i32 @add_edge(%struct.graph* %1, i32 4, i32 5)
%6 = tail call i32 @add_edge(%struct.graph* %1, i32 5, i32 2)
%7 = tail call i32 @add_edge(%struct.graph* %1, i32 2, i32 1)
%8 = tail call i64 @detect_cycle(%struct.graph* %1)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0)
%11 = tail call i32 @printf(i8* dereferenceable(1) %10)
ret void
}