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

/* Variables and functions */
scalar_t__ isPrime(int);
int *prime_1_svc(int *argp, struct svc_req *rqstp) {
  static int result;
  int n, number, counter;
  n = *argp;
  counter = 1;
  number = 2;
  while (counter < n) {
    number++;
    if (isPrime(number)) {
      counter++;
    }
  }
  result = number;
  return &result;
}


x86 assembly (clang, -O0):
<prime_1_svc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116c <prime_1_svc+0x5c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <isPrime@plt>
cmp    $0x0,%rax
je     1167 <prime_1_svc+0x57>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <prime_1_svc+0x27>
mov    -0x18(%rbp),%eax
mov    %eax,0x2eb7(%rip)
lea    0x2eb0(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_1_svc>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%r14d
mov    $0x2,%ebx
cmp    $0x2,%r14d
jl     1146 <prime_1_svc+0x36>
mov    $0x2,%ebx
mov    $0x1,%ebp
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %ebx,%edi
call   1030 <isPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
cmp    %r14d,%ebp
jl     1130 <prime_1_svc+0x20>
mov    %ebx,0x2ee0(%rip)
lea    0x2ed9(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.svc_req = type { i32 }
@prime_1_svc.result = internal global i32 0
define i32* @prime_1_svc(i32* %0, %struct.svc_req* %1) {
%3 = alloca i32*
%4 = alloca %struct.svc_req*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store %struct.svc_req* %1, %struct.svc_req** %4
%8 = load i32*, i32** %3
%9 = load i32, i32* %8
store i32 %9, i32* %5
store i32 1, i32* %7
store i32 2, i32* %6
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i64 @isPrime(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %23
23: ; preds = %20, %14
br label %10
24: ; preds = %10
%25 = load i32, i32* %6
store i32 %25, i32* @prime_1_svc.result
ret i32* @prime_1_svc.result
}

LLVM IR (-O2):
%struct.svc_req = type { i32 }
@prime_1_svc.result = internal global i32 0
define i32* @prime_1_svc(i32* nocapture %0, %struct.svc_req* nocapture readnone %1) {
%3 = load i32, i32* %0
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %14
5: ; preds = %2, %5
%6 = phi i32 [ %12, %5 ], [ 1, %2 ]
%7 = phi i32 [ %8, %5 ], [ 2, %2 ]
%8 = add nuw nsw i32 %7, 1
%9 = tail call i64 @isPrime(i32 %8)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %6, %11
%13 = icmp slt i32 %12, %3
br i1 %13, label %5, label %14
14: ; preds = %5, %2
%15 = phi i32 [ 2, %2 ], [ %8, %5 ]
store i32 %15, i32* @prime_1_svc.result
ret i32* @prime_1_svc.result
}