#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  int primer = 0;
  int c = 3;
  printf("\nTorna un 1 si el nombre es primer i 0 si no ho es.\n");
  printf("\nIntrodueix un nombre per saber si es primer:");
  scanf("%d", &n);
  if (n == 2 || n == 1) {
    primer = 1;
  } else if (!(n % 2 == 0)) {
    do {
      if (n % c == 0 && n != c) {
        break;
      } else if (n % c == 0) {
        primer = 1;
      }
      c += 2;
    } while (!primer);
  }
  printf("%d\n", primer);
  return primer;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x2,-0x8(%rbp)
je     117d <main+0x5d>
cmpl   $0x1,-0x8(%rbp)
jne    1189 <main+0x69>
movl   $0x1,-0xc(%rbp)
jmp    1203 <main+0xe3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11fe <main+0xde>
jmp    11a2 <main+0x82>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11c3 <main+0xa3>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11c3 <main+0xa3>
jmp    11f9 <main+0xd9>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11da <main+0xba>
movl   $0x1,-0xc(%rbp)
jmp    11df <main+0xbf>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a2 <main+0x82>
jmp    11fe <main+0xde>
jmp    1203 <main+0xe3>
mov    -0xc(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
lea    -0x1(%rcx),%eax
mov    $0x1,%ebx
cmp    $0x2,%eax
jb     1196 <main+0x66>
test   $0x1,%cl
je     1194 <main+0x64>
mov    $0x3,%esi
jmp    1187 <main+0x57>
nopl   (%rax)
add    $0x2,%esi
test   %edx,%edx
je     1196 <main+0x66>
mov    %ecx,%eax
cltd
idiv   %esi
cmp    %esi,%ecx
je     1180 <main+0x50>
test   %edx,%edx
jne    1180 <main+0x50>
xor    %ebx,%ebx
lea    0xe94(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [53 x i8] c"\0ATorna un 1 si el nombre es primer i 0 si no ho es.\0A\00"
@.str.1 = [46 x i8] c"\0AIntrodueix un nombre per saber si es primer:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 3, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %10, %0
store i32 1, i32* %3
br label %45
14: ; preds = %10
%15 = load i32, i32* %2
%16 = srem i32 %15, 2
%17 = icmp eq i32 %16, 0
br i1 %17, label %44, label %18
18: ; preds = %14
br label %19
19: ; preds = %39, %18
%20 = load i32, i32* %2
%21 = load i32, i32* %4
%22 = srem i32 %20, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %43
29: ; preds = %24, %19
%30 = load i32, i32* %2
%31 = load i32, i32* %4
%32 = srem i32 %30, %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %3
br label %35
35: ; preds = %34, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 2
store i32 %38, i32* %4
br label %39
39: ; preds = %36
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
%42 = xor i1 %41, true
br i1 %42, label %19, label %43
43: ; preds = %39, %28
br label %44
44: ; preds = %43, %14
br label %45
45: ; preds = %44, %13
%46 = load i32, i32* %3
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"\0AIntrodueix un nombre per saber si es primer:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [52 x i8] c"\0ATorna un 1 si el nombre es primer i 0 si no ho es.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add i32 %6, -1
%8 = icmp ult i32 %7, 2
br i1 %8, label %21, label %9
9: ; preds = %0
%10 = and i32 %6, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9, %18
%13 = phi i32 [ %20, %18 ], [ 3, %9 ]
%14 = srem i32 %6, %13
%15 = icmp ne i32 %14, 0
%16 = icmp eq i32 %6, %13
%17 = or i1 %16, %15
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = icmp eq i32 %14, 0
%20 = add nuw nsw i32 %13, 2
br i1 %19, label %21, label %12
21: ; preds = %12, %18, %0, %9
%22 = phi i32 [ 0, %9 ], [ 1, %0 ], [ 0, %12 ], [ 1, %18 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
ret i32 %22
}