#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 node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ addNewNode(struct node *, int);
int /*<<< orphan*/ addNode(struct node *, struct node *);
int findCircularVal(struct node *);
struct node *initNode(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  struct node *ptr = initNode(6);
  struct node *circle = initNode(3);
  addNewNode(ptr, 1);
  addNewNode(ptr, 7);
  addNewNode(ptr, 2);
  addNewNode(ptr, 10);
  addNewNode(circle, 20);
  addNewNode(circle, 30);
  addNewNode(circle, 40);
  addNode(circle, circle);
  addNode(ptr, circle);
  printf("Value at start of circular list: %i\n", findCircularVal(ptr));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x6,%edi
call   1040 <initNode@plt>
mov    %rax,-0x8(%rbp)
mov    $0x3,%edi
call   1040 <initNode@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <addNewNode@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
call   1050 <addNewNode@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1050 <addNewNode@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1050 <addNewNode@plt>
mov    -0x10(%rbp),%rdi
mov    $0x14,%esi
call   1050 <addNewNode@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1e,%esi
call   1050 <addNewNode@plt>
mov    -0x10(%rbp),%rdi
mov    $0x28,%esi
call   1050 <addNewNode@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <addNode@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <addNode@plt>
mov    -0x8(%rbp),%rdi
call   1030 <findCircularVal@plt>
mov    %eax,%esi
lea    0xdfe(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x6,%edi
call   1040 <initNode@plt>
mov    %rax,%r14
mov    $0x3,%edi
call   1040 <initNode@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <addNewNode@plt>
mov    %r14,%rdi
mov    $0x7,%esi
call   1050 <addNewNode@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1050 <addNewNode@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <addNewNode@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1050 <addNewNode@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1050 <addNewNode@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
call   1050 <addNewNode@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1070 <addNode@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <addNode@plt>
mov    %r14,%rdi
call   1030 <findCircularVal@plt>
lea    0xe12(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [37 x i8] c"Value at start of circular list: %i\0A\00"
define i32 @main() {
%1 = alloca %struct.node*
%2 = alloca %struct.node*
%3 = call %struct.node* @initNode(i32 6)
store %struct.node* %3, %struct.node** %1
%4 = call %struct.node* @initNode(i32 3)
store %struct.node* %4, %struct.node** %2
%5 = load %struct.node*, %struct.node** %1
%6 = call i32 @addNewNode(%struct.node* %5, i32 1)
%7 = load %struct.node*, %struct.node** %1
%8 = call i32 @addNewNode(%struct.node* %7, i32 7)
%9 = load %struct.node*, %struct.node** %1
%10 = call i32 @addNewNode(%struct.node* %9, i32 2)
%11 = load %struct.node*, %struct.node** %1
%12 = call i32 @addNewNode(%struct.node* %11, i32 10)
%13 = load %struct.node*, %struct.node** %2
%14 = call i32 @addNewNode(%struct.node* %13, i32 20)
%15 = load %struct.node*, %struct.node** %2
%16 = call i32 @addNewNode(%struct.node* %15, i32 30)
%17 = load %struct.node*, %struct.node** %2
%18 = call i32 @addNewNode(%struct.node* %17, i32 40)
%19 = load %struct.node*, %struct.node** %2
%20 = load %struct.node*, %struct.node** %2
%21 = call i32 @addNode(%struct.node* %19, %struct.node* %20)
%22 = load %struct.node*, %struct.node** %1
%23 = load %struct.node*, %struct.node** %2
%24 = call i32 @addNode(%struct.node* %22, %struct.node* %23)
%25 = load %struct.node*, %struct.node** %1
%26 = call i32 @findCircularVal(%struct.node* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [37 x i8] c"Value at start of circular list: %i\0A\00"
define i32 @main() {
%1 = tail call %struct.node* @initNode(i32 6)
%2 = tail call %struct.node* @initNode(i32 3)
%3 = tail call i32 @addNewNode(%struct.node* %1, i32 1)
%4 = tail call i32 @addNewNode(%struct.node* %1, i32 7)
%5 = tail call i32 @addNewNode(%struct.node* %1, i32 2)
%6 = tail call i32 @addNewNode(%struct.node* %1, i32 10)
%7 = tail call i32 @addNewNode(%struct.node* %2, i32 20)
%8 = tail call i32 @addNewNode(%struct.node* %2, i32 30)
%9 = tail call i32 @addNewNode(%struct.node* %2, i32 40)
%10 = tail call i32 @addNode(%struct.node* %2, %struct.node* %2)
%11 = tail call i32 @addNode(%struct.node* %1, %struct.node* %2)
%12 = tail call i32 @findCircularVal(%struct.node* %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %12)
ret i32 0
}