#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*/ heap_swim(struct node **, int);
void heap_insert(struct node **heap, struct node *node, int *nr, int alloc) {
  if (!nr)
    return;
  if (*nr + 1 >= alloc)
    return;
  heap[*nr] = node;
  *nr = *nr + 1;
  heap_swim(heap, *nr - 1);
}


x86 assembly (clang, -O0):
<heap_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1137 <heap_insert+0x27>
jmp    1182 <heap_insert+0x72>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jl     114e <heap_insert+0x3e>
jmp    1182 <heap_insert+0x72>
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
sub    $0x1,%esi
call   1030 <heap_swim@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heap_insert>:
test   %rdx,%rdx
je     112f <heap_insert+0x1f>
movslq (%rdx),%rax
lea    0x1(%rax),%r8d
cmp    %ecx,%r8d
jge    112f <heap_insert+0x1f>
mov    %rsi,(%rdi,%rax,8)
mov    %r8d,(%rdx)
mov    %eax,%esi
jmp    1030 <heap_swim@plt>
ret

LLVM IR (-O0):
%struct.node = type { i32 }
define void @heap_insert(%struct.node** %0, %struct.node* %1, i32* %2, i32 %3) {
%5 = alloca %struct.node**
%6 = alloca %struct.node*
%7 = alloca i32*
%8 = alloca i32
store %struct.node** %0, %struct.node*** %5
store %struct.node* %1, %struct.node** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %4
br label %35
12: ; preds = %4
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = load i32, i32* %8
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %12
br label %35
19: ; preds = %12
%20 = load %struct.node*, %struct.node** %6
%21 = load %struct.node**, %struct.node*** %5
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds %struct.node*, %struct.node** %21, i64 %24
store %struct.node* %20, %struct.node** %25
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = load i32*, i32** %7
store i32 %28, i32* %29
%30 = load %struct.node**, %struct.node*** %5
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = sub nsw i32 %32, 1
%34 = call i32 @heap_swim(%struct.node** %30, i32 %33)
br label %35
35: ; preds = %19, %18, %11
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
define void @heap_insert(%struct.node** %0, %struct.node* %1, i32* %2, i32 %3) {
%5 = icmp eq i32* %2, null
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = icmp slt i32 %8, %3
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds %struct.node*, %struct.node** %0, i64 %11
store %struct.node* %1, %struct.node** %12
store i32 %8, i32* %2
%13 = tail call i32 @heap_swim(%struct.node** %0, i32 %7)
br label %14
14: ; preds = %6, %4, %10
ret void
}