#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 USHRT_MAX;
int atoi(char *);
char getchar();
int /*<<< orphan*/ is_digit(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ more_then(char *, int);
int /*<<< orphan*/ perror_exit(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ s_fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(void) {
  int minutes;
  static char input[7];
  while (1) {
    memset(input, 0, 7);
    printf("minutes (0 ~ %hu): ", USHRT_MAX);
    if (!s_fgets(input, 7, stdin))
      perror_exit("fgets failed");
    if (input[0] == '\n')
      continue;
    if (more_then(input, 6)) {
      printf("invalid input!\n");
      while (getchar() != '\n')
        ;
      continue;
    }
    if (!is_digit(input)) {
      printf("invalid input!\n");
      continue;
    }
    minutes = atoi(input);
    if ((minutes > USHRT_MAX) || (minutes < 0)) {
      printf("out of range!\n");
      continue;
    }
    break;
  }
  printf("%d hours and %d minutes\n", (minutes / 60), (minutes % 60));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2ece(%rip),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1040 <memset@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
lea    0x2e9b(%rip),%rdi
mov    $0x7,%esi
call   1070 <s_fgets@plt>
cmp    $0x0,%eax
jne    11e8 <main+0x68>
lea    0xe31(%rip),%rdi
call   1090 <perror_exit@plt>
movsbl 0x2e75(%rip),%eax
cmp    $0xa,%eax
jne    11fd <main+0x7d>
jmp    118f <main+0xf>
lea    0x2e60(%rip),%rdi
mov    $0x6,%esi
call   1080 <more_then@plt>
cmp    $0x0,%rax
je     1243 <main+0xc3>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     123e <main+0xbe>
jmp    1226 <main+0xa6>
jmp    118f <main+0xf>
lea    0x2e1a(%rip),%rdi
call   1060 <is_digit@plt>
cmp    $0x0,%eax
jne    126b <main+0xeb>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118f <main+0xf>
lea    0x2df2(%rip),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d64(%rip),%rcx
cmp    (%rcx),%eax
jg     1296 <main+0x116>
cmpl   $0x0,-0x8(%rbp)
jge    12a9 <main+0x129>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118f <main+0xf>
jmp    12ae <main+0x12e>
mov    -0x8(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x8(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x2eca(%rip),%rbx
mov    0x2e3f(%rip),%r13
lea    0xe50(%rip),%r14
mov    0x2e29(%rip),%rbp
lea    0xe56(%rip),%r15
lea    0xe83(%rip),%r12
jmp    11d0 <main+0x40>
call   1030 <puts@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1080 <s_fgets@plt>
test   %eax,%eax
je     1210 <main+0x80>
cmpb   $0xa,0x2e64(%rip)
je     11d0 <main+0x40>
jmp    1221 <main+0x91>
nopl   0x0(%rax)
mov    %r15,%rdi
call   10a0 <perror_exit@plt>
cmpb   $0xa,0x2e4d(%rip)
je     11d0 <main+0x40>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1090 <more_then@plt>
test   %rax,%rax
je     124d <main+0xbd>
mov    %r12,%rdi
call   1030 <puts@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    1240 <main+0xb0>
jmp    11d0 <main+0x40>
mov    %rbx,%rdi
call   1070 <is_digit@plt>
mov    %r12,%rdi
test   %eax,%eax
je     11c7 <main+0x37>
mov    %rbx,%rdi
call   10b0 <atoi@plt>
lea    0xdcb(%rip),%rdi
test   %eax,%eax
js     11c7 <main+0x37>
lea    0xdbc(%rip),%rdi
cmp    0x0(%r13),%eax
jg     11c7 <main+0x37>
mov    %eax,%ecx
mov    $0x88888889,%esi
imul   %rcx,%rsi
shr    $0x25,%rsi
imul   $0x3c,%esi,%ecx
sub    %ecx,%eax
lea    0xd7e(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.input = internal global [7 x i8] zeroinitializer
@.str = [20 x i8] c"minutes (0 ~ %hu): \00"
@USHRT_MAX = global i32 0
@stdin = global i32 0
@.str.1 = [13 x i8] c"fgets failed\00"
@.str.2 = [16 x i8] c"invalid input!\0A\00"
@.str.3 = [15 x i8] c"out of range!\0A\00"
@.str.4 = [25 x i8] c"%d hours and %d minutes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %0, %16, %27, %31, %41
%4 = call i32 @memset(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 0, i32 7)
%5 = load i32, i32* @USHRT_MAX
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @s_fgets(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 7, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i32 @perror_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
%13 = load i8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0)
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %12
br label %3
17: ; preds = %12
%18 = call i64 @more_then(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 6)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %26, %20
%23 = call signext i8 (...) @getchar()
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %22
br label %22
27: ; preds = %22
br label %3
28: ; preds = %17
%29 = call i32 @is_digit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %3
33: ; preds = %28
%34 = call i32 @atoi(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0))
store i32 %34, i32* %2
%35 = load i32, i32* %2
%36 = load i32, i32* @USHRT_MAX
%37 = icmp sgt i32 %35, %36
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = load i32, i32* %2
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38, %33
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %3
43: ; preds = %38
br label %44
44: ; preds = %43
%45 = load i32, i32* %2
%46 = sdiv i32 %45, 60
%47 = load i32, i32* %2
%48 = srem i32 %47, 60
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %48)
ret i32 0
}

LLVM IR (-O2):
@main.input = internal global [7 x i8] zeroinitializer
@.str = [20 x i8] c"minutes (0 ~ %hu): \00"
@USHRT_MAX = global i32 0
@stdin = global i32 0
@.str.1 = [13 x i8] c"fgets failed\00"
@.str.4 = [25 x i8] c"%d hours and %d minutes\0A\00"
@str.5 = [14 x i8] c"out of range!\00"
@str.6 = [15 x i8] c"invalid input!\00"
define i32 @main() {
br label %1
1: ; preds = %27, %0
%2 = tail call i32 @memset(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 0, i32 7)
%3 = load i32, i32* @USHRT_MAX
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @stdin
%6 = tail call i32 @s_fgets(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 7, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0)
%12 = icmp eq i8 %11, 10
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = tail call i64 @more_then(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0), i32 6)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0))
br label %18
18: ; preds = %18, %16
%19 = tail call signext i8 (...) @getchar()
%20 = icmp eq i8 %19, 10
br i1 %20, label %27, label %18
21: ; preds = %13
%22 = tail call i32 @is_digit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21, %28
%25 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %28 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.6, i64 0, i64 0), %21 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
br label %27
27: ; preds = %18, %24, %10
br label %1
28: ; preds = %21
%29 = tail call i32 @atoi(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @main.input, i64 0, i64 0))
%30 = load i32, i32* @USHRT_MAX
%31 = icmp sgt i32 %29, %30
%32 = icmp slt i32 %29, 0
%33 = or i1 %32, %31
br i1 %33, label %24, label %34
34: ; preds = %28
%35 = udiv i32 %29, 60
%36 = urem i32 %29, 60
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36)
ret i32 0
}