#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 /*<<< orphan*/ gp2x_video_flip();
int /*<<< orphan*/ sprintf(unsigned char *, char *, int);
float sqrt(int);
int /*<<< orphan*/ v_putcad(int, int, int, int, unsigned char *);
void prim() {
  unsigned char cad[256];
  char p = 0;
  int primnumber;
  int l = 1;
  float g = 0;
  int i = 3;
  while (i != 500000) {
    int m = 2;
    float temp = sqrt(i);
    float ifloat = (float)i;
    if (temp == (int)temp) {
      m = i;
      p = 1;
    }
    while (m < temp) {
      g = ifloat / m;
      if (g == (int)g) {
        m = i;
        p = 1;
      }
      m++;
    }
    if (p == 0) {
      l += 1;
      primnumber = i;
      sprintf(cad, "%u is primnumber", i);
      v_putcad(1, 13, 0xffffff, 0xB00000, cad);
      gp2x_video_flip();
    }
    p = 0;
    i++;
  }
}


x86 assembly (clang, -O0):
<prim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movb   $0x0,-0x101(%rbp)
movl   $0x1,-0x10c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x110(%rbp)
ff
movl   $0x3,-0x114(%rbp)
cmpl   $0x7a120,-0x114(%rbp)
je     12ee <prim+0x1ae>
movl   $0x2,-0x118(%rbp)
mov    -0x114(%rbp),%edi
call   1050 <sqrt@plt>
movss  %xmm0,-0x11c(%rbp)
ff
cvtsi2ssl -0x114(%rbp),%xmm0
ff
movss  %xmm0,-0x120(%rbp)
ff
movss  -0x11c(%rbp),%xmm0
ff
cvttss2si -0x11c(%rbp),%eax
ff
cvtsi2ss %eax,%xmm1
ucomiss %xmm1,%xmm0
jne    11e4 <prim+0xa4>
jp     11e4 <prim+0xa4>
mov    -0x114(%rbp),%eax
mov    %eax,-0x118(%rbp)
movb   $0x1,-0x101(%rbp)
jmp    11e9 <prim+0xa9>
cvtsi2ssl -0x118(%rbp),%xmm1
ff
movss  -0x11c(%rbp),%xmm0
ff
ucomiss %xmm1,%xmm0
jbe    1268 <prim+0x128>
movss  -0x120(%rbp),%xmm0
ff
cvtsi2ssl -0x118(%rbp),%xmm1
ff
divss  %xmm1,%xmm0
movss  %xmm0,-0x110(%rbp)
ff
movss  -0x110(%rbp),%xmm0
ff
cvttss2si -0x110(%rbp),%eax
ff
cvtsi2ss %eax,%xmm1
ucomiss %xmm1,%xmm0
jne    1254 <prim+0x114>
jp     1254 <prim+0x114>
mov    -0x114(%rbp),%eax
mov    %eax,-0x118(%rbp)
movb   $0x1,-0x101(%rbp)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11e9 <prim+0xa9>
movsbl -0x101(%rbp),%eax
cmp    $0x0,%eax
jne    12d3 <prim+0x193>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x114(%rbp),%eax
mov    %eax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x114(%rbp),%edx
lea    0xd59(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x100(%rbp),%r8
mov    $0x1,%edi
mov    $0xd,%esi
mov    $0xffffff,%edx
mov    $0xb00000,%ecx
call   1030 <v_putcad@plt>
mov    $0x0,%al
call   1040 <gp2x_video_flip@plt>
movb   $0x0,-0x101(%rbp)
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1171 <prim+0x31>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prim>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    $0x3,%ebx
mov    $0x2,%ebp
lea    0xea2(%rip),%r14
mov    %rsp,%r15
jmp    117f <prim+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    $0x7a120,%ebx
je     1235 <prim+0xf5>
mov    %ebx,%edi
call   1050 <sqrt@plt>
cvttps2dq %xmm0,%xmm1
cvtdq2ps %xmm1,%xmm1
movaps %xmm0,%xmm2
cmpeqss %xmm1,%xmm2
movd   %xmm2,%eax
and    $0x1,%eax
ucomiss %xmm1,%xmm0
mov    %ebx,%ecx
cmovne %ebp,%ecx
cmovp  %ebp,%ecx
xorps  %xmm2,%xmm2
cvtsi2ss %ecx,%xmm2
ucomiss %xmm2,%xmm0
jbe    11f8 <prim+0xb8>
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
nopw   0x0(%rax,%rax,1)
movaps %xmm1,%xmm3
divss  %xmm2,%xmm3
cvttps2dq %xmm3,%xmm2
cvtdq2ps %xmm2,%xmm2
ucomiss %xmm2,%xmm3
mov    %ebx,%edx
cmovne %ecx,%edx
cmovp  %ecx,%edx
movzbl %al,%ecx
mov    $0x1,%eax
cmovne %ecx,%eax
cmovp  %ecx,%eax
add    $0x1,%edx
xorps  %xmm2,%xmm2
cvtsi2ss %edx,%xmm2
ucomiss %xmm2,%xmm0
mov    %edx,%ecx
ja     11c0 <prim+0x80>
test   %al,%al
jne    1170 <prim+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    $0x1,%edi
mov    $0xd,%esi
mov    $0xffffff,%edx
mov    $0xb00000,%ecx
mov    %r15,%r8
call   1030 <v_putcad@plt>
xor    %eax,%eax
call   1040 <gp2x_video_flip@plt>
jmp    1170 <prim+0x30>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%u is primnumber\00"
define void @prim() {
%1 = alloca [256 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float
store i8 0, i8* %2
store i32 1, i32* %4
store float 0.000000e+00, float* %5
store i32 3, i32* %6
br label %10
10: ; preds = %60, %0
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 500000
br i1 %12, label %13, label %63
13: ; preds = %10
store i32 2, i32* %7
%14 = load i32, i32* %6
%15 = call float @sqrt(i32 %14)
store float %15, float* %8
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to float
store float %17, float* %9
%18 = load float, float* %8
%19 = load float, float* %8
%20 = fptosi float %19 to i32
%21 = sitofp i32 %20 to float
%22 = fcmp oeq float %18, %21
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = load i32, i32* %6
store i32 %24, i32* %7
store i8 1, i8* %2
br label %25
25: ; preds = %23, %13
br label %26
26: ; preds = %43, %25
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to float
%29 = load float, float* %8
%30 = fcmp olt float %28, %29
br i1 %30, label %31, label %46
31: ; preds = %26
%32 = load float, float* %9
%33 = load i32, i32* %7
%34 = sitofp i32 %33 to float
%35 = fdiv float %32, %34
store float %35, float* %5
%36 = load float, float* %5
%37 = load float, float* %5
%38 = fptosi float %37 to i32
%39 = sitofp i32 %38 to float
%40 = fcmp oeq float %36, %39
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = load i32, i32* %6
store i32 %42, i32* %7
store i8 1, i8* %2
br label %43
43: ; preds = %41, %31
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %26
46: ; preds = %26
%47 = load i8, i8* %2
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
%53 = load i32, i32* %6
store i32 %53, i32* %3
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%55 = load i32, i32* %6
%56 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%58 = call i32 @v_putcad(i32 1, i32 13, i32 16777215, i32 11534336, i8* %57)
%59 = call i32 (...) @gp2x_video_flip()
br label %60
60: ; preds = %50, %46
store i8 0, i8* %2
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %10
63: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"%u is primnumber\00"
define void @prim() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %34
%4 = phi i32 [ 3, %0 ], [ %35, %34 ]
%5 = call float @sqrt(i32 %4)
%6 = sitofp i32 %4 to float
%7 = fptosi float %5 to i32
%8 = sitofp i32 %7 to float
%9 = fcmp oeq float %5, %8
%10 = select i1 %9, i32 %4, i32 2
%11 = zext i1 %9 to i8
%12 = sitofp i32 %10 to float
%13 = fcmp ogt float %5, %12
br i1 %13, label %14, label %27
14: ; preds = %3, %14
%15 = phi float [ %25, %14 ], [ %12, %3 ]
%16 = phi i8 [ %23, %14 ], [ %11, %3 ]
%17 = phi i32 [ %24, %14 ], [ %10, %3 ]
%18 = fdiv float %6, %15
%19 = fptosi float %18 to i32
%20 = sitofp i32 %19 to float
%21 = fcmp oeq float %18, %20
%22 = select i1 %21, i32 %4, i32 %17
%23 = select i1 %21, i8 1, i8 %16
%24 = add nsw i32 %22, 1
%25 = sitofp i32 %24 to float
%26 = fcmp ogt float %5, %25
br i1 %26, label %14, label %27
27: ; preds = %14, %3
%28 = phi i8 [ %11, %3 ], [ %23, %14 ]
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
%32 = call i32 @v_putcad(i32 1, i32 13, i32 16777215, i32 11534336, i8* %2)
%33 = call i32 (...) @gp2x_video_flip()
br label %34
34: ; preds = %30, %27
%35 = add nuw nsw i32 %4, 1
%36 = icmp eq i32 %35, 500000
br i1 %36, label %37, label %3
37: ; preds = %34
ret void
}