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

/* Variables and functions */
struct list *createList();
int /*<<< orphan*/ insertFirst(struct list *, int);
int n_prime(int);
struct list *kPrimes(int k, int start, int end) {
  struct list *result = createList();
  for (int i = end; i >= start; --i) {
    if (n_prime(i) == k)
      insertFirst(result, i);
  }
  return result;
}


x86 assembly (clang, -O0):
<kPrimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1050 <createList@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     118e <kPrimes+0x5e>
mov    -0x1c(%rbp),%edi
call   1040 <n_prime@plt>
cmp    -0x4(%rbp),%eax
jne    117b <kPrimes+0x4b>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <insertFirst@plt>
jmp    1180 <kPrimes+0x50>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <kPrimes+0x22>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kPrimes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
xor    %eax,%eax
call   1050 <createList@plt>
mov    %rax,%r15
cmp    %ebp,%ebx
jge    1169 <kPrimes+0x39>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%eax
cmp    %ebp,%ebx
mov    %eax,%ebx
jle    114c <kPrimes+0x1c>
mov    %ebx,%edi
call   1040 <n_prime@plt>
cmp    %r14d,%eax
jne    1160 <kPrimes+0x30>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <insertFirst@plt>
jmp    1160 <kPrimes+0x30>

LLVM IR (-O0):
%struct.list = type { i32 }
define %struct.list* @kPrimes(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.list*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call %struct.list* (...) @createList()
store %struct.list* %9, %struct.list** %7
%10 = load i32, i32* %6
store i32 %10, i32* %8
br label %11
11: ; preds = %25, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp sge i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i32, i32* %8
%17 = call i32 @n_prime(i32 %16)
%18 = load i32, i32* %4
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load %struct.list*, %struct.list** %7
%22 = load i32, i32* %8
%23 = call i32 @insertFirst(%struct.list* %21, i32 %22)
br label %24
24: ; preds = %20, %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, -1
store i32 %27, i32* %8
br label %11
28: ; preds = %11
%29 = load %struct.list*, %struct.list** %7
ret %struct.list* %29
}

LLVM IR (-O2):
%struct.list = type { i32 }
define %struct.list* @kPrimes(i32 %0, i32 %1, i32 %2) {
%4 = tail call %struct.list* (...) @createList()
%5 = icmp slt i32 %2, %1
br i1 %5, label %6, label %7
6: ; preds = %13, %3
ret %struct.list* %4
7: ; preds = %3, %13
%8 = phi i32 [ %14, %13 ], [ %2, %3 ]
%9 = tail call i32 @n_prime(i32 %8)
%10 = icmp eq i32 %9, %0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @insertFirst(%struct.list* %4, i32 %8)
br label %13
13: ; preds = %7, %11
%14 = add nsw i32 %8, -1
%15 = icmp sgt i32 %8, %1
br i1 %15, label %7, label %6
}