#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 digit_sum(int);
scalar_t__ is_prime(int);
int print_menu();
int /*<<< orphan*/ print_table(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int c, num;
  do {
    printf("\nPrograma de funciones. Porfavor seleccione una opcion: \n");
    c = print_menu();
    if (c != 4 && c != -1) {
      printf("Ingrese un numero: ");
      scanf("%d", &num);
    }
    if (c == 1)
      print_table(num);
    else if (c == 2)
      printf("\nEl numero %d %ses primo\n", num, (is_prime(num)) ? "" : "no ");
    else if (c == 3)
      printf("\nLa suma de los digitos de %d es %d\n", num, digit_sum(num));
    else if (c == -1)
      printf("\nOpcion invalida.\n");
  } while (c != 4);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <print_menu@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11b9 <main+0x59>
cmpl   $0xffffffff,-0x8(%rbp)
je     11b9 <main+0x59>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11d0 <main+0x70>
mov    -0xc(%rbp),%edi
call   1030 <print_table@plt>
jmp    126e <main+0x10e>
cmpl   $0x2,-0x8(%rbp)
jne    1217 <main+0xb7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <is_prime@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rcx
lea    0xe76(%rip),%rdx
lea    0xe3d(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1269 <main+0x109>
cmpl   $0x3,-0x8(%rbp)
jne    1247 <main+0xe7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <digit_sum@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x104>
cmpl   $0xffffffff,-0x8(%rbp)
jne    125f <main+0xff>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x104>
jmp    1269 <main+0x109>
jmp    126e <main+0x10e>
jmp    1273 <main+0x113>
cmpl   $0x4,-0x8(%rbp)
jne    116f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xed8(%rip),%rbx
lea    0xf0a(%rip),%r14
lea    0xe70(%rip),%r15
lea    0xe7d(%rip),%r12
lea    0x4(%rsp),%r13
jmp    11a8 <main+0x38>
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <print_menu@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x30>
mov    %eax,%ebp
cmp    $0x4,%eax
je     124a <main+0xda>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
cmp    $0x3,%ebp
je     1228 <main+0xb8>
cmp    $0x2,%ebp
je     11f6 <main+0x86>
cmp    $0x1,%ebp
jne    11a8 <main+0x38>
mov    0x4(%rsp),%edi
call   1030 <print_table@plt>
jmp    11a8 <main+0x38>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1060 <is_prime@plt>
test   %rax,%rax
lea    0xe4e(%rip),%rdx
lea    0xe1f(%rip),%rax
cmove  %rax,%rdx
lea    0xdfa(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a8 <main+0x38>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1070 <digit_sum@plt>
lea    0xdfb(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a8 <main+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"\0APrograma de funciones. Porfavor seleccione una opcion: \0A\00"
@.str.1 = [20 x i8] c"Ingrese un numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"\0AEl numero %d %ses primo\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c"no \00"
@.str.6 = [37 x i8] c"\0ALa suma de los digitos de %d es %d\0A\00"
@.str.7 = [19 x i8] c"\0AOpcion invalida.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %49, %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @print_menu()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 4
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %15
15: ; preds = %12, %9, %4
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %3
%20 = call i32 @print_table(i32 %19)
br label %48
21: ; preds = %15
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = load i32, i32* %3
%26 = load i32, i32* %3
%27 = call i64 @is_prime(i32 %26)
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %30)
br label %47
32: ; preds = %21
%33 = load i32, i32* %2
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* %3
%37 = load i32, i32* %3
%38 = call i32 @digit_sum(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %36, i32 %38)
br label %46
40: ; preds = %32
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
br label %46
46: ; preds = %45, %35
br label %47
47: ; preds = %46, %24
br label %48
48: ; preds = %47, %18
br label %49
49: ; preds = %48
%50 = load i32, i32* %2
%51 = icmp ne i32 %50, 4
br i1 %51, label %4, label %52
52: ; preds = %49
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Ingrese un numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"\0AEl numero %d %ses primo\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c"no \00"
@.str.6 = [37 x i8] c"\0ALa suma de los digitos de %d es %d\0A\00"
@str = [57 x i8] c"\0APrograma de funciones. Porfavor seleccione una opcion: \00"
@str.8 = [18 x i8] c"\0AOpcion invalida.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %18, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%5 = call i32 (...) @print_menu()
switch i32 %5, label %6 [
i32 -1, label %23
i32 4, label %25
]
6: ; preds = %3
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
switch i32 %5, label %18 [
i32 1, label %9
i32 2, label %12
i32 3, label %19
]
9: ; preds = %6
%10 = load i32, i32* %1
%11 = call i32 @print_table(i32 %10)
br label %18
12: ; preds = %6
%13 = load i32, i32* %1
%14 = call i64 @is_prime(i32 %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %13, i8* %16)
br label %18
18: ; preds = %12, %23, %19, %9, %6
br label %3
19: ; preds = %6
%20 = load i32, i32* %1
%21 = call i32 @digit_sum(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %20, i32 %21)
br label %18
23: ; preds = %3
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %18
25: ; preds = %3
ret i32 0
}