#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*/ insert_in_sorted(struct node **, int);
int rand();
struct node *randSortedList(int n) {
  struct node *head = NULL;
  for (int i = 0; i < n; i++) {
    insert_in_sorted(&head, rand() % 20);
  }
  return head;
}


x86 assembly (clang, -O0):
<randSortedList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116e <randSortedList+0x4e>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    -0x10(%rbp),%rdi
call   1030 <insert_in_sorted@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <randSortedList+0x1a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randSortedList>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
test   %edi,%edi
jle    1179 <randSortedList+0x59>
mov    %edi,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %r14,%rdi
call   1030 <insert_in_sorted@plt>
add    $0xffffffff,%ebx
jne    1140 <randSortedList+0x20>
mov    (%rsp),%rax
jmp    117b <randSortedList+0x5b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.node = type { i32 }
define %struct.node* @randSortedList(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.node*
%4 = alloca i32
store i32 %0, i32* %2
store %struct.node* null, %struct.node** %3
store i32 0, i32* %4
br label %5
5: ; preds = %13, %1
%6 = load i32, i32* %4
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 20
%12 = call i32 @insert_in_sorted(%struct.node** %3, i32 %11)
br label %13
13: ; preds = %9
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %5
16: ; preds = %5
%17 = load %struct.node*, %struct.node** %3
ret %struct.node* %17
}

LLVM IR (-O2):
%struct.node = type { i32 }
define %struct.node* @randSortedList(i32 %0) {
%2 = alloca %struct.node*
%3 = bitcast %struct.node** %2 to i8*
store %struct.node* null, %struct.node** %2
%4 = icmp sgt i32 %0, 0
br i1 %4, label %9, label %7
5: ; preds = %9
%6 = load %struct.node*, %struct.node** %2
br label %7
7: ; preds = %5, %1
%8 = phi %struct.node* [ %6, %5 ], [ null, %1 ]
ret %struct.node* %8
9: ; preds = %1, %9
%10 = phi i32 [ %14, %9 ], [ 0, %1 ]
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 20
%13 = call i32 @insert_in_sorted(%struct.node** %2, i32 %12)
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, %0
br i1 %15, label %5, label %9
}