#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 */
struct Servel {
  int dummy;
};

/* Variables and functions */
int agregarDiputado(struct Servel *, int /*<<< orphan*/);
int /*<<< orphan*/ ingresarRut();
int numeroDistritoConMasDiputado(struct Servel *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void menu(struct Servel *s) {
  int opcion = 0, respuesta = 0;
  do {
    printf("%s", "\n\n");
    printf("%s", "1.- Agregar Diputado\n");
    printf("%s", "2.- Mostrar Distrito con mas Diputados\n");
    printf("%s", "0.- Salir\n");
    scanf("%d", &opcion);
    switch (opcion) {
    case 1:
      respuesta = agregarDiputado(s, ingresarRut());
      if (respuesta == 0) {
        printf("Hubo un error. Caso1");
      }
      if (respuesta == 0) {
        printf("El Diputado se agrego al sistema");
      }
      if (respuesta == -1) {
        printf("El Diputado ya existe");
      }
      break;
    case 2:
      respuesta = numeroDistritoConMasDiputado(s);
      if (respuesta == -1) {
        printf("Hubo un error. Caso 2");
      } else {
        printf("El Distrito %d tiene mas Diputados", respuesta);
      }
      break;
    }
  } while (opcion != 0);
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe8f(%rip),%rdi
mov    %rdi,-0x20(%rbp)
lea    0xe87(%rip),%rsi
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x15(%rbp),%al
lea    0xe72(%rip),%rsi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x15(%rbp),%al
lea    0xe75(%rip),%rsi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x15(%rbp),%al
lea    0xe8a(%rip),%rsi
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11f4 <menu+0xa4>
jmp    11e3 <menu+0x93>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     125e <menu+0x10e>
jmp    129d <menu+0x14d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <ingresarRut@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <agregarDiputado@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1229 <menu+0xd9>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1241 <menu+0xf1>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1259 <menu+0x109>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129d <menu+0x14d>
mov    -0x8(%rbp),%rdi
call   1060 <numeroDistritoConMasDiputado@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1287 <menu+0x137>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1298 <menu+0x148>
mov    -0x10(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129d <menu+0x14d>
jmp    12a2 <menu+0x152>
cmpl   $0x0,-0xc(%rbp)
jne    116a <menu+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
lea    0xf0d(%rip),%r15
lea    0xf1b(%rip),%r12
lea    0xf3b(%rip),%r13
lea    0xe6e(%rip),%rbp
lea    0x4(%rsp),%r14
jmp    11b3 <menu+0x53>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1262 <menu+0x102>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
je     1230 <menu+0xd0>
cmp    $0x1,%eax
jne    11ab <menu+0x4b>
xor    %eax,%eax
call   1050 <ingresarRut@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <agregarDiputado@plt>
cmp    $0xffffffff,%eax
je     1256 <menu+0xf6>
test   %eax,%eax
jne    11a7 <menu+0x47>
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf9(%rip),%rdi
jmp    11a0 <menu+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <numeroDistritoConMasDiputado@plt>
cmp    $0xffffffff,%eax
je     1199 <menu+0x39>
lea    0xe1d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a7 <menu+0x47>
lea    0xddc(%rip),%rdi
jmp    11a0 <menu+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Servel = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [22 x i8] c"1.- Agregar Diputado\0A\00"
@.str.3 = [40 x i8] c"2.- Mostrar Distrito con mas Diputados\0A\00"
@.str.4 = [11 x i8] c"0.- Salir\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [21 x i8] c"Hubo un error. Caso1\00"
@.str.7 = [33 x i8] c"El Diputado se agrego al sistema\00"
@.str.8 = [22 x i8] c"El Diputado ya existe\00"
@.str.9 = [22 x i8] c"Hubo un error. Caso 2\00"
@.str.10 = [35 x i8] c"El Distrito %d tiene mas Diputados\00"
define void @menu(%struct.Servel* %0) {
%2 = alloca %struct.Servel*
%3 = alloca i32
%4 = alloca i32
store %struct.Servel* %0, %struct.Servel** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %43, %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
switch i32 %11, label %42 [
i32 1, label %12
i32 2, label %31
]
12: ; preds = %5
%13 = load %struct.Servel*, %struct.Servel** %2
%14 = call i32 (...) @ingresarRut()
%15 = call i32 @agregarDiputado(%struct.Servel* %13, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
br label %42
31: ; preds = %5
%32 = load %struct.Servel*, %struct.Servel** %2
%33 = call i32 @numeroDistritoConMasDiputado(%struct.Servel* %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %41
38: ; preds = %31
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %36
br label %42
42: ; preds = %5, %41, %30
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = icmp ne i32 %44, 0
br i1 %45, label %5, label %46
46: ; preds = %43
ret void
}

LLVM IR (-O2):
%struct.Servel = type { i32 }
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [21 x i8] c"Hubo un error. Caso1\00"
@.str.7 = [33 x i8] c"El Diputado se agrego al sistema\00"
@.str.8 = [22 x i8] c"El Diputado ya existe\00"
@.str.9 = [22 x i8] c"Hubo un error. Caso 2\00"
@.str.10 = [35 x i8] c"El Distrito %d tiene mas Diputados\00"
@str = [2 x i8] c"\0A\00"
@str.11 = [21 x i8] c"1.- Agregar Diputado\00"
@str.12 = [39 x i8] c"2.- Mostrar Distrito con mas Diputados\00"
@str.13 = [10 x i8] c"0.- Salir\00"
define void @menu(%struct.Servel* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %28, %1
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.12, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.13, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
switch i32 %10, label %28 [
i32 1, label %11
i32 2, label %19
]
11: ; preds = %4
%12 = call i32 (...) @ingresarRut()
%13 = call i32 @agregarDiputado(%struct.Servel* %0, i32 %12)
switch i32 %13, label %26 [
i32 0, label %14
i32 -1, label %17
]
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %26
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %26
19: ; preds = %4
%20 = call i32 @numeroDistritoConMasDiputado(%struct.Servel* %0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i32 %20)
br label %26
26: ; preds = %22, %24, %17, %11, %14
%27 = load i32, i32* %2
br label %28
28: ; preds = %26, %4
%29 = phi i32 [ %27, %26 ], [ %10, %4 ]
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %4
31: ; preds = %28
ret void
}