#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 */

/* Variables and functions */
int ft_is_prime(int);
int ft_add_prime_sum(int nb) {
  int i;
  int sum;
  sum = 0;
  i = 2;
  while (i <= nb) {
    if (ft_is_prime(i) == 1) {
      sum += i;
      i++;
    } else
      i++;
  }
  return (sum);
}


x86 assembly (clang, -O0):
<ft_add_prime_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     116b <ft_add_prime_sum+0x5b>
mov    -0x8(%rbp),%edi
call   1030 <ft_is_prime@plt>
cmp    $0x1,%eax
jne    115d <ft_add_prime_sum+0x4d>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <ft_add_prime_sum+0x56>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <ft_add_prime_sum+0x19>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_add_prime_sum>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
cmp    $0x2,%edi
jge    1122 <ft_add_prime_sum+0x12>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%r14d
neg    %r14d
mov    $0x2,%ebx
xor    %ebp,%ebp
jmp    1155 <ft_add_prime_sum+0x45>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ecx,%ebp
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     111b <ft_add_prime_sum+0xb>
mov    %ebx,%edi
call   1030 <ft_is_prime@plt>
mov    %ebx,%ecx
cmp    $0x1,%eax
je     1140 <ft_add_prime_sum+0x30>
xor    %ecx,%ecx
jmp    1140 <ft_add_prime_sum+0x30>

LLVM IR (-O0):
define i32 @ft_add_prime_sum(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 2, i32* %3
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i32 @ft_is_prime(i32 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = add nsw i32 %15, %14
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %22
19: ; preds = %9
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %22
22: ; preds = %19, %13
br label %5
23: ; preds = %5
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @ft_add_prime_sum(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %12, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 0, %1 ]
%5 = phi i32 [ %10, %3 ], [ 2, %1 ]
%6 = tail call i32 @ft_is_prime(i32 %5)
%7 = icmp eq i32 %6, 1
%8 = select i1 %7, i32 %5, i32 0
%9 = add nuw nsw i32 %8, %4
%10 = add nuw i32 %5, 1
%11 = icmp eq i32 %5, %0
br i1 %11, label %12, label %3
12: ; preds = %3, %1
%13 = phi i32 [ 0, %1 ], [ %9, %3 ]
ret i32 %13
}