#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ sched_desalojar_tarea(int);
int /*<<< orphan*/ sched_inicializar();
unsigned short sched_montar_idle();
unsigned short sched_proxima_tarea();
int sched_tarea_actual();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int c;
  unsigned short i;
  sched_inicializar();
  srand(time(NULL));
  while (1) {
    printf("> ");
    c = getchar();
    if (c == 'q')
      break;
    i = sched_proxima_tarea();
    printf("~ Proximo indice: %#x\n", i >> 3);
    if (rand() % 8 == 7) {
      printf("\n--- IDLE ---\n");
      i = sched_montar_idle();
      printf("~ Proximo indice: %#x\n", i >> 3);
    }
    if (rand() % 64 == 0) {
      printf("\n--- Se muere la tarea actual [%u] ---\n", sched_tarea_actual());
      sched_desalojar_tarea(sched_tarea_actual());
      sched_montar_idle();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <sched_inicializar@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x71,-0x8(%rbp)
jne    11ed <main+0x4d>
jmp    129c <main+0xfc>
mov    $0x0,%al
call   1040 <sched_proxima_tarea@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%esi
sar    $0x3,%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    1253 <main+0xb3>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10a0 <sched_montar_idle@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%esi
sar    $0x3,%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1297 <main+0xf7>
mov    $0x0,%al
call   1030 <sched_tarea_actual@plt>
mov    %eax,%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <sched_tarea_actual@plt>
mov    %eax,%edi
call   10b0 <sched_desalojar_tarea@plt>
mov    $0x0,%al
call   10a0 <sched_montar_idle@plt>
jmp    11c6 <main+0x26>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <sched_inicializar@plt>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0x71,%eax
jne    11f5 <main+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe07(%rip),%rbx
lea    0xe3f(%rip),%r14
lea    0xe10(%rip),%r15
lea    0xdef(%rip),%r12
jmp    1241 <main+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10d0 <rand@plt>
test   $0x3f,%al
je     12a0 <main+0xf0>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0x71,%eax
je     11e7 <main+0x37>
xor    %eax,%eax
call   1050 <sched_proxima_tarea@plt>
movzwl %ax,%esi
shr    $0x3,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
cmp    $0x7,%eax
jne    1220 <main+0x70>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10b0 <sched_montar_idle@plt>
movzwl %ax,%esi
shr    $0x3,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1220 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <sched_tarea_actual@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <sched_tarea_actual@plt>
mov    %eax,%edi
call   10c0 <sched_desalojar_tarea@plt>
xor    %eax,%eax
call   10b0 <sched_montar_idle@plt>
jmp    122b <main+0x7b>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@.str.1 = [23 x i8] c"~ Proximo indice: %#x\0A\00"
@.str.2 = [15 x i8] c"\0A--- IDLE ---\0A\00"
@.str.3 = [40 x i8] c"\0A--- Se muere la tarea actual [%u] ---\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i16
store i32 0, i32* %1
%4 = call i32 (...) @sched_inicializar()
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %39
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 113
br i1 %11, label %12, label %13
12: ; preds = %7
br label %40
13: ; preds = %7
%14 = call zeroext i16 (...) @sched_proxima_tarea()
store i16 %14, i16* %3
%15 = load i16, i16* %3
%16 = zext i16 %15 to i32
%17 = ashr i32 %16, 3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 8
%21 = icmp eq i32 %20, 7
br i1 %21, label %22, label %29
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%24 = call zeroext i16 (...) @sched_montar_idle()
store i16 %24, i16* %3
%25 = load i16, i16* %3
%26 = zext i16 %25 to i32
%27 = ashr i32 %26, 3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22, %13
%30 = call i32 (...) @rand()
%31 = srem i32 %30, 64
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = call i32 (...) @sched_tarea_actual()
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = call i32 (...) @sched_tarea_actual()
%37 = call i32 @sched_desalojar_tarea(i32 %36)
%38 = call zeroext i16 (...) @sched_montar_idle()
br label %39
39: ; preds = %33, %29
br label %7
40: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@.str.1 = [23 x i8] c"~ Proximo indice: %#x\0A\00"
@.str.3 = [40 x i8] c"\0A--- Se muere la tarea actual [%u] ---\0A\00"
@str = [14 x i8] c"\0A--- IDLE ---\00"
define i32 @main() {
%1 = tail call i32 (...) @sched_inicializar()
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @getchar()
%6 = icmp eq i32 %5, 113
br i1 %6, label %35, label %7
7: ; preds = %0, %31
%8 = tail call zeroext i16 (...) @sched_proxima_tarea()
%9 = lshr i16 %8, 3
%10 = zext i16 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 8
%14 = icmp eq i32 %13, 7
br i1 %14, label %15, label %21
15: ; preds = %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%17 = tail call zeroext i16 (...) @sched_montar_idle()
%18 = lshr i16 %17, 3
%19 = zext i16 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %15, %7
%22 = tail call i32 (...) @rand()
%23 = and i32 %22, 63
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = tail call i32 (...) @sched_tarea_actual()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = tail call i32 (...) @sched_tarea_actual()
%29 = tail call i32 @sched_desalojar_tarea(i32 %28)
%30 = tail call zeroext i16 (...) @sched_montar_idle()
br label %31
31: ; preds = %25, %21
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%33 = tail call i32 (...) @getchar()
%34 = icmp eq i32 %33, 113
br i1 %34, label %35, label %7
35: ; preds = %31, %0
ret i32 0
}