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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
struct s_linked_list *build_linked_list(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct s_linked_list *find_median(struct s_linked_list *, int *);
int /*<<< orphan*/ free_node(struct s_linked_list *);
int /*<<< orphan*/ print_list(struct s_linked_list *, struct s_linked_list *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct s_linked_list *list, *median;
  int pos = 0, len, data_len;
  if (argc < 2 || !argv[1]) {
    printf("%s list_size [data_len]\n", argv[0]);
    printf("\tlist_size: Number of nodes to generate.\n");
    printf("\tdata_len:  Length of the random data.\n");
    exit(EXIT_FAILURE);
  }
  srand((unsigned int)time(NULL));
  len = atoi(argv[1]);
  data_len = argv[2] ? atoi(argv[2]) : 8;
  if (!(list = build_linked_list(len, data_len)))
    exit(EXIT_FAILURE);
  median = find_median(list, &pos);
  printf("The median node is at position %d\n", pos);
  if (len <= 8)
    print_list(list, median);
  free_node(list);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11c6 <main+0x36>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1205 <main+0x75>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1249 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    1256 <main+0xc6>
mov    $0x8,%eax
mov    %eax,-0x30(%rbp)
jmp    1256 <main+0xc6>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <build_linked_list@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1283 <main+0xf3>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1090 <find_median@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x8,-0x28(%rbp)
jg     12bc <main+0x12c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <print_list@plt>
mov    -0x18(%rbp),%rdi
call   1080 <free_node@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
cmp    $0x2,%edi
jl     124b <main+0xab>
cmpq   $0x0,0x8(%rbx)
je     124b <main+0xab>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
test   %rdi,%rdi
je     11f2 <main+0x52>
call   10b0 <atoi@plt>
mov    %eax,%esi
jmp    11f7 <main+0x57>
mov    $0x8,%esi
mov    %ebp,%edi
call   1040 <build_linked_list@plt>
test   %rax,%rax
je     1274 <main+0xd4>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   10a0 <find_median@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x8,%ebp
jg     1238 <main+0x98>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <print_list@plt>
mov    %rbx,%rdi
call   1090 <free_node@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xdab(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.s_linked_list = type { i32 }
@.str = [25 x i8] c"%s list_size [data_len]\0A\00"
@.str.1 = [42 x i8] c"\09list_size: Number of nodes to generate.\0A\00"
@.str.2 = [40 x i8] c"\09data_len: Length of the random data.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [35 x i8] c"The median node is at position %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.s_linked_list*
%7 = alloca %struct.s_linked_list*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %27, label %18
18: ; preds = %13, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %13
%28 = call i64 @time(i32* null)
%29 = trunc i64 %28 to i32
%30 = call i32 @srand(i32 %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %44
39: ; preds = %27
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
br label %45
44: ; preds = %27
br label %45
45: ; preds = %44, %39
%46 = phi i32 [ %43, %39 ], [ 8, %44 ]
store i32 %46, i32* %10
%47 = load i32, i32* %9
%48 = load i32, i32* %10
%49 = call %struct.s_linked_list* @build_linked_list(i32 %47, i32 %48)
store %struct.s_linked_list* %49, %struct.s_linked_list** %6
%50 = icmp ne %struct.s_linked_list* %49, null
br i1 %50, label %54, label %51
51: ; preds = %45
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %45
%55 = load %struct.s_linked_list*, %struct.s_linked_list** %6
%56 = call %struct.s_linked_list* @find_median(%struct.s_linked_list* %55, i32* %8)
store %struct.s_linked_list* %56, %struct.s_linked_list** %7
%57 = load i32, i32* %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %9
%60 = icmp sle i32 %59, 8
br i1 %60, label %61, label %65
61: ; preds = %54
%62 = load %struct.s_linked_list*, %struct.s_linked_list** %6
%63 = load %struct.s_linked_list*, %struct.s_linked_list** %7
%64 = call i32 @print_list(%struct.s_linked_list* %62, %struct.s_linked_list* %63)
br label %65
65: ; preds = %61, %54
%66 = load %struct.s_linked_list*, %struct.s_linked_list** %6
%67 = call i32 @free_node(%struct.s_linked_list* %66)
ret i32 0
}

LLVM IR (-O2):
%struct.s_linked_list = type { i32 }
@.str = [25 x i8] c"%s list_size [data_len]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [35 x i8] c"The median node is at position %d\0A\00"
@str = [41 x i8] c"\09list_size: Number of nodes to generate.\00"
@str.4 = [39 x i8] c"\09data_len: Length of the random data.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp slt i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %6, %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.4, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = tail call i64 @time(i32* null)
%19 = trunc i64 %18 to i32
%20 = tail call i32 @srand(i32 %19)
%21 = load i8*, i8** %7
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = tail call i32 @atoi(i8* %24)
br label %28
28: ; preds = %17, %26
%29 = phi i32 [ %27, %26 ], [ 8, %17 ]
%30 = tail call %struct.s_linked_list* @build_linked_list(i32 %22, i32 %29)
%31 = icmp eq %struct.s_linked_list* %30, null
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = call %struct.s_linked_list* @find_median(%struct.s_linked_list* %30, i32* %3)
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = icmp slt i32 %22, 9
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @print_list(%struct.s_linked_list* %30, %struct.s_linked_list* %36)
br label %42
42: ; preds = %40, %35
%43 = call i32 @free_node(%struct.s_linked_list* %30)
ret i32 0
}