#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*/ printf(char *, int, ...);
int sqrt(int);
int main() {
  int i;
  for (i = 2; i < sqrt(1973); i++)
    if ((1973 % i == 0)) {
      printf("NUM is  %d * %d and so it is not prime\n", i, 1973 / i);
      return 0;
    }
  printf("%d IS prime\n", 1973);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x7b5,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jge    11a0 <main+0x80>
mov    $0x7b5,%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    118d <main+0x6d>
mov    -0x8(%rbp),%esi
mov    $0x7b5,%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ba <main+0x9a>
jmp    1192 <main+0x72>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
lea    0xe81(%rip),%rdi
mov    $0x7b5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x7b5,%edi
call   1040 <sqrt@plt>
cmp    $0x3,%eax
jl     115e <main+0x3e>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x7b5,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
je     1173 <main+0x53>
add    $0x1,%ebx
mov    $0x7b5,%edi
call   1040 <sqrt@plt>
cmp    %eax,%ebx
jl     1140 <main+0x20>
lea    0xec3(%rip),%rdi
mov    $0x7b5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1185 <main+0x65>
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"NUM is %d * %d and so it is not prime\0A\00"
@.str.1 = [13 x i8] c"%d IS prime\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
br label %3
3: ; preds = %17, %0
%4 = load i32, i32* %2
%5 = call i32 @sqrt(i32 1973)
%6 = icmp slt i32 %4, %5
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = load i32, i32* %2
%9 = srem i32 1973, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = sdiv i32 1973, %13
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
store i32 0, i32* %1
br label %22
16: ; preds = %7
br label %17
17: ; preds = %16
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %3
20: ; preds = %3
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1973)
store i32 0, i32* %1
br label %22
22: ; preds = %20, %11
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [40 x i8] c"NUM is %d * %d and so it is not prime\0A\00"
@.str.1 = [13 x i8] c"%d IS prime\0A\00"
define i32 @main() {
%1 = tail call i32 @sqrt(i32 1973)
%2 = icmp sgt i32 %1, 2
br i1 %2, label %3, label %14
3: ; preds = %0, %10
%4 = phi i32 [ %11, %10 ], [ 2, %0 ]
%5 = urem i32 1973, %4
%6 = udiv i32 1973, %4
%7 = icmp eq i32 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %6)
br label %16
10: ; preds = %3
%11 = add nuw nsw i32 %4, 1
%12 = tail call i32 @sqrt(i32 1973)
%13 = icmp slt i32 %11, %12
br i1 %13, label %3, label %14
14: ; preds = %10, %0
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1973)
br label %16
16: ; preds = %14, %8
ret i32 0
}