#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 genera_primo(int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int numero;
  int listaprimos[100];
  int j, i = 0;
  int primo = 1;
  printf("Este programa descompone un numero dado por el usuario en factores");
  printf(" primos. \n");
  printf("Introduce un numero mayor que 1: ");
  scanf("%d", &numero);
  printf("\n");
  printf("%d: {", numero);
  if (numero == 1)
    listaprimos[0] = 1;
  while (numero != 1) {
    primo = genera_primo(primo);
    if ((numero % primo) == 0) {
      numero = numero / primo;
      listaprimos[i] = primo;
      i++;
      primo--;
    }
    if (numero == 1)
      break;
  }
  for (j = 0; j < i - 1; j++) {
    printf("%d,", listaprimos[j]);
  }
  printf("%d}", listaprimos[j]);
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1a8(%rbp)
movl   $0x1,-0x1ac(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11d3 <main+0x93>
movl   $0x1,-0x1a0(%rbp)
jmp    11d8 <main+0x98>
cmpl   $0x1,-0x8(%rbp)
je     1259 <main+0x119>
mov    -0x1ac(%rbp),%edi
call   1030 <genera_primo@plt>
mov    %eax,-0x1ac(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x1ac(%rbp)
cmp    $0x0,%edx
jne    1245 <main+0x105>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x1ac(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x1ac(%rbp),%ecx
movslq -0x1a8(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x1ac(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1ac(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1254 <main+0x114>
jmp    1259 <main+0x119>
jmp    11d8 <main+0x98>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
mov    -0x1a8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12aa <main+0x16a>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1263 <main+0x123>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xe8d(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xef3(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xec8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%esi
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x1,0xc(%rsp)
jne    11d4 <main+0x74>
movl   $0x1,0x10(%rsp)
jmp    1249 <main+0xe9>
mov    $0x1,%edi
jmp    11e5 <main+0x85>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%ecx
je     120e <main+0xae>
call   1030 <genera_primo@plt>
mov    %eax,%edi
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
cltd
idiv   %edi
test   %edx,%edx
jne    11e0 <main+0x80>
mov    %eax,0xc(%rsp)
movslq %ebx,%rbx
mov    %edi,0x10(%rsp,%rbx,4)
add    $0x1,%ebx
add    $0xffffffff,%edi
mov    %eax,%ecx
jmp    11e0 <main+0x80>
cmp    $0x2,%ebx
jl     1249 <main+0xe9>
add    $0xffffffff,%ebx
mov    %ebx,%r15d
lea    0xe4e(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1230 <main+0xd0>
jmp    124c <main+0xec>
xor    %r15d,%r15d
mov    0x10(%rsp,%r15,4),%esi
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Este programa descompone un numero dado por el usuario en factores\00"
@.str.1 = [11 x i8] c" primos. \0A\00"
@.str.2 = [34 x i8] c"Introduce un numero mayor que 1: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [6 x i8] c"%d: {\00"
@.str.6 = [4 x i8] c"%d,\00"
@.str.7 = [4 x i8] c"%d}\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 1, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
store i32 1, i32* %17
br label %18
18: ; preds = %16, %0
br label %19
19: ; preds = %45, %18
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %46
22: ; preds = %19
%23 = load i32, i32* %6
%24 = call i32 @genera_primo(i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %2
%26 = load i32, i32* %6
%27 = srem i32 %25, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %22
%30 = load i32, i32* %2
%31 = load i32, i32* %6
%32 = sdiv i32 %30, %31
store i32 %32, i32* %2
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %35
store i32 %33, i32* %36
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
br label %41
41: ; preds = %29, %22
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %45
44: ; preds = %41
br label %46
45: ; preds = %41
br label %19
46: ; preds = %44, %19
store i32 0, i32* %4
br label %47
47: ; preds = %58, %46
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = sub nsw i32 %49, 1
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %61
52: ; preds = %47
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %52
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %47
61: ; preds = %47
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = call i32 (...) @getchar()
%68 = call i32 (...) @getchar()
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [67 x i8] c"Este programa descompone un numero dado por el usuario en factores\00"
@.str.2 = [34 x i8] c"Introduce un numero mayor que 1: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d: {\00"
@.str.6 = [4 x i8] c"%d,\00"
@.str.7 = [4 x i8] c"%d}\00"
@str = [10 x i8] c" primos. \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 @putchar(i32 10)
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
store i32 1, i32* %15
br label %48
16: ; preds = %0, %29
%17 = phi i32 [ %31, %29 ], [ 0, %0 ]
%18 = phi i32 [ %32, %29 ], [ 1, %0 ]
%19 = call i32 @genera_primo(i32 %18)
%20 = load i32, i32* %1
%21 = srem i32 %20, %19
%22 = sdiv i32 %20, %19
%23 = icmp eq i32 %21, 0
br i1 %23, label %24, label %29
24: ; preds = %16
store i32 %22, i32* %1
%25 = sext i32 %17 to i64
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %25
store i32 %19, i32* %26
%27 = add nsw i32 %17, 1
%28 = add nsw i32 %19, -1
br label %29
29: ; preds = %24, %16
%30 = phi i32 [ %22, %24 ], [ %20, %16 ]
%31 = phi i32 [ %27, %24 ], [ %17, %16 ]
%32 = phi i32 [ %28, %24 ], [ %19, %16 ]
%33 = icmp eq i32 %30, 1
br i1 %33, label %34, label %16
34: ; preds = %29
%35 = add i32 %31, -1
%36 = icmp sgt i32 %31, 1
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = zext i32 %35 to i64
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %44, %39 ]
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = icmp eq i64 %44, %38
br i1 %45, label %46, label %39
46: ; preds = %39
%47 = zext i32 %35 to i64
br label %48
48: ; preds = %34, %14, %46
%49 = phi i64 [ %47, %46 ], [ 0, %14 ], [ 0, %34 ]
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = call i32 (...) @getchar()
%54 = call i32 (...) @getchar()
ret i32 0
}