#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*/ print(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void ex8() {
  print("\n------------------------------\n");
  int hora_inicial, hora_final, minuto_inicial, minuto_final;
  print("Informe o horario de inicio do jogo:");
  printf("Horas: ");
  scanf("%d", &hora_inicial);
  while (!(hora_inicial >= 0 && hora_inicial < 24)) {
    printf("Valor invalido, tente novamente: ");
    scanf("%d", &hora_inicial);
  }
  printf("Minutos: ");
  scanf("%d", &minuto_inicial);
  while (!(minuto_inicial >= 0 && minuto_inicial < 60)) {
    printf("Valor invalido, tente novamente: ");
    scanf("%d", &minuto_inicial);
  }
  print("Informe o horario de termino do jogo:");
  printf("Horas: ");
  scanf("%d", &hora_final);
  while (!(hora_final >= 0 && hora_final < 24)) {
    printf("Valor invalido, tente novamente: ");
    scanf("%d", &hora_final);
  }
  printf("Minutos: ");
  scanf("%d", &minuto_final);
  while (!(minuto_final >= 0 && minuto_final < 60)) {
    printf("Valor invalido, tente novamente: ");
    scanf("%d", &minuto_final);
  }
  int duracao;
  duracao =
      (hora_final * 60 + minuto_final) - (hora_inicial * 60 + minuto_inicial);
  if (duracao < 0) {
    duracao += 1440;
  }
  printf("\nA duracao do jogo foi de: %02dh:%02dm\n", duracao / 60,
         duracao % 60);
  print("\n------------------------------\n");
}


x86 assembly (clang, -O0):
<ex8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
call   1040 <print@plt>
lea    0xed6(%rip),%rdi
call   1040 <print@plt>
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x15(%rbp)
jl     1187 <ex8+0x57>
cmpl   $0x18,-0x4(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    1199 <ex8+0x69>
jmp    11bc <ex8+0x8c>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
jmp    116e <ex8+0x3e>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7d(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x16(%rbp)
jl     11f3 <ex8+0xc3>
cmpl   $0x3c,-0xc(%rbp)
setl   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    1205 <ex8+0xd5>
jmp    1228 <ex8+0xf8>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe34(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
jmp    11da <ex8+0xaa>
lea    0xe4e(%rip),%rdi
call   1040 <print@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe05(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x17(%rbp)
jl     126b <ex8+0x13b>
cmpl   $0x18,-0x8(%rbp)
setl   %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    127d <ex8+0x14d>
jmp    12a0 <ex8+0x170>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdbc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1252 <ex8+0x122>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd99(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x18(%rbp)
jl     12d7 <ex8+0x1a7>
cmpl   $0x3c,-0x10(%rbp)
setl   %al
mov    %al,-0x18(%rbp)
mov    -0x18(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    12e9 <ex8+0x1b9>
jmp    130c <ex8+0x1dc>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd50(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
jmp    12be <ex8+0x18e>
imul   $0x3c,-0x8(%rbp),%eax
add    -0x10(%rbp),%eax
imul   $0x3c,-0x4(%rbp),%ecx
add    -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1334 <ex8+0x204>
mov    -0x14(%rbp),%eax
add    $0x5a0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc9f(%rip),%rdi
call   1040 <print@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex8>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
call   1040 <print@plt>
lea    0xed5(%rip),%rdi
call   1040 <print@plt>
lea    0xeee(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x18,0x8(%rsp)
jb     11ac <ex8+0x7c>
lea    0xed3(%rip),%r14
lea    0xec9(%rip),%r15
lea    0x8(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x17,0x8(%rsp)
ja     1190 <ex8+0x60>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmpl   $0x3c,(%rsp)
jb     11fb <ex8+0xcb>
lea    0xe7b(%rip),%r14
lea    0xe71(%rip),%r15
mov    %rsp,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x3b,(%rsp)
ja     11e0 <ex8+0xb0>
lea    0xe7b(%rip),%rdi
call   1040 <print@plt>
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe32(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x18,0x4(%rsp)
jb     125c <ex8+0x12c>
lea    0xe1d(%rip),%r14
lea    0xe13(%rip),%r15
lea    0x4(%rsp),%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x17,0x4(%rsp)
ja     1240 <ex8+0x110>
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xddd(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3c,%eax
jb     12be <ex8+0x18e>
lea    0xdc6(%rip),%r14
lea    0xdbc(%rip),%r15
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3b,%eax
ja     12a0 <ex8+0x170>
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%ecx
imul   $0x3c,%ecx,%ecx
sub    (%rsp),%eax
mov    %eax,%edx
add    %ecx,%edx
lea    0x5a0(%rax,%rcx,1),%eax
cmovns %edx,%eax
movslq %eax,%rdx
imul   $0xffffffff88888889,%rdx,%rsi
shr    $0x20,%rsi
add    %edx,%esi
mov    %esi,%eax
shr    $0x1f,%eax
sar    $0x5,%esi
add    %eax,%esi
imul   $0x3c,%esi,%eax
sub    %eax,%edx
lea    0xda3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xcf2(%rip),%rdi
call   1040 <print@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A------------------------------\0A\00"
@.str.1 = [37 x i8] c"Informe o horario de inicio do jogo:\00"
@.str.2 = [8 x i8] c"Horas: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"Valor invalido, tente novamente: \00"
@.str.5 = [10 x i8] c"Minutos: \00"
@.str.6 = [38 x i8] c"Informe o horario de termino do jogo:\00"
@.str.7 = [40 x i8] c"\0AA duracao do jogo foi de: %02dh:%02dm\0A\00"
define void @ex8() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %1
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 24
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
%18 = xor i1 %17, true
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
br label %10
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %25
25: ; preds = %34, %22
%26 = load i32, i32* %3
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 60
br label %31
31: ; preds = %28, %25
%32 = phi i1 [ false, %25 ], [ %30, %28 ]
%33 = xor i1 %32, true
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %25
37: ; preds = %31
%38 = call i32 @print(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %41
41: ; preds = %50, %37
%42 = load i32, i32* %2
%43 = icmp sge i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %2
%46 = icmp slt i32 %45, 24
br label %47
47: ; preds = %44, %41
%48 = phi i1 [ false, %41 ], [ %46, %44 ]
%49 = xor i1 %48, true
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %41
53: ; preds = %47
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
br label %56
56: ; preds = %65, %53
%57 = load i32, i32* %4
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %4
%61 = icmp slt i32 %60, 60
br label %62
62: ; preds = %59, %56
%63 = phi i1 [ false, %56 ], [ %61, %59 ]
%64 = xor i1 %63, true
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
br label %56
68: ; preds = %62
%69 = load i32, i32* %2
%70 = mul nsw i32 %69, 60
%71 = load i32, i32* %4
%72 = add nsw i32 %70, %71
%73 = load i32, i32* %1
%74 = mul nsw i32 %73, 60
%75 = load i32, i32* %3
%76 = add nsw i32 %74, %75
%77 = sub nsw i32 %72, %76
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %68
%81 = load i32, i32* %5
%82 = add nsw i32 %81, 1440
store i32 %82, i32* %5
br label %83
83: ; preds = %80, %68
%84 = load i32, i32* %5
%85 = sdiv i32 %84, 60
%86 = load i32, i32* %5
%87 = srem i32 %86, 60
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %85, i32 %87)
%89 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"\0A------------------------------\0A\00"
@.str.1 = [37 x i8] c"Informe o horario de inicio do jogo:\00"
@.str.2 = [8 x i8] c"Horas: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [34 x i8] c"Valor invalido, tente novamente: \00"
@.str.5 = [10 x i8] c"Minutos: \00"
@.str.6 = [38 x i8] c"Informe o horario de termino do jogo:\00"
@.str.7 = [40 x i8] c"\0AA duracao do jogo foi de: %02dh:%02dm\0A\00"
define void @ex8() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = tail call i32 @print(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp ugt i32 %13, 23
br i1 %14, label %15, label %20
15: ; preds = %0, %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = icmp ugt i32 %18, 23
br i1 %19, label %15, label %20
20: ; preds = %15, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = icmp ugt i32 %23, 59
br i1 %24, label %25, label %30
25: ; preds = %20, %25
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%28 = load i32, i32* %3
%29 = icmp ugt i32 %28, 59
br i1 %29, label %25, label %30
30: ; preds = %25, %20
%31 = call i32 @print(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%34 = load i32, i32* %2
%35 = icmp ugt i32 %34, 23
br i1 %35, label %36, label %41
36: ; preds = %30, %36
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%39 = load i32, i32* %2
%40 = icmp ugt i32 %39, 23
br i1 %40, label %36, label %41
41: ; preds = %36, %30
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%44 = load i32, i32* %4
%45 = icmp ugt i32 %44, 59
br i1 %45, label %46, label %51
46: ; preds = %41, %46
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%49 = load i32, i32* %4
%50 = icmp ugt i32 %49, 59
br i1 %50, label %46, label %51
51: ; preds = %46, %41
%52 = phi i32 [ %44, %41 ], [ %49, %46 ]
%53 = load i32, i32* %2
%54 = load i32, i32* %1
%55 = load i32, i32* %3
%56 = sub i32 %53, %54
%57 = mul i32 %56, 60
%58 = sub i32 %52, %55
%59 = add i32 %58, %57
%60 = icmp slt i32 %59, 0
%61 = add nsw i32 %59, 1440
%62 = select i1 %60, i32 %61, i32 %59
%63 = sdiv i32 %62, 60
%64 = srem i32 %62, 60
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %63, i32 %64)
%66 = call i32 @print(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret void
}