#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(void) {
  int hour, minutes;
  bool pm = false;
  printf("Enter a 24-hour time: ");
  scanf("%2d:%2d", &hour, &minutes);
  if (hour > 24 || hour < 0 || minutes > 59 || minutes < 0) {
    printf("Invalid time. Only appropriate values are permitted.");
    return 1;
  }
  if (hour >= 12) {
    pm = true;
    if (hour > 12) {
      hour = hour - 12;
    }
  } else {
    if (hour == 0) {
      hour = 12;
    }
  }
  printf("Equialent 12-hour time: %2d:%02d ", hour, minutes);
  if (pm) {
    printf("PM\n");
  } else {
    printf("AM\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
cmpl   $0x18,-0x8(%rbp)
jg     1180 <main+0x60>
cmpl   $0x0,-0x8(%rbp)
jl     1180 <main+0x60>
cmpl   $0x3b,-0xc(%rbp)
jg     1180 <main+0x60>
cmpl   $0x0,-0xc(%rbp)
jge    119a <main+0x7a>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121f <main+0xff>
cmpl   $0xc,-0x8(%rbp)
jl     11c3 <main+0xa3>
movl   $0x1,-0x10(%rbp)
cmpl   $0xc,-0x8(%rbp)
jle    11be <main+0x9e>
mov    -0x8(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x8(%rbp)
jmp    11d9 <main+0xb9>
cmpl   $0x0,-0x8(%rbp)
jne    11d4 <main+0xb4>
movl   $0xc,-0x8(%rbp)
jmp    11d9 <main+0xb9>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
je     120a <main+0xea>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1218 <main+0xf8>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
cmp    $0x18,%esi
ja     119f <main+0x6f>
mov    0xc(%rsp),%edx
cmp    $0x3b,%edx
jg     119f <main+0x6f>
test   %edx,%edx
js     119f <main+0x6f>
cmp    $0xc,%esi
jb     11b4 <main+0x84>
mov    $0xc,%eax
je     1184 <main+0x54>
add    $0xfffffff4,%esi
mov    %esi,0x8(%rsp)
mov    %esi,%eax
lea    0xec9(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
jmp    11dc <main+0xac>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    11e1 <main+0xb1>
test   %esi,%esi
jne    11c5 <main+0x95>
movl   $0xc,0x8(%rsp)
mov    $0xc,%esi
lea    0xe88(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Enter a 24-hour time: \00"
@.str.1 = [8 x i8] c"%2d:%2d\00"
@.str.2 = [53 x i8] c"Invalid time. Only appropriate values are permitted.\00"
@.str.3 = [34 x i8] c"Equialent 12-hour time: %2d:%02d \00"
@.str.4 = [4 x i8] c"PM\0A\00"
@.str.5 = [4 x i8] c"AM\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 24
br i1 %8, label %18, label %9
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 59
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %12, %9, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
20: ; preds = %15
%21 = load i32, i32* %2
%22 = icmp sge i32 %21, 12
br i1 %22, label %23, label %30
23: ; preds = %20
store i32 1, i32* %4
%24 = load i32, i32* %2
%25 = icmp sgt i32 %24, 12
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %2
%28 = sub nsw i32 %27, 12
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %23
br label %35
30: ; preds = %20
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 12, i32* %2
br label %34
34: ; preds = %33, %30
br label %35
35: ; preds = %34, %29
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %45
43: ; preds = %35
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %41
store i32 0, i32* %1
br label %46
46: ; preds = %45, %18
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [23 x i8] c"Enter a 24-hour time: \00"
@.str.1 = [8 x i8] c"%2d:%2d\00"
@.str.2 = [53 x i8] c"Invalid time. Only appropriate values are permitted.\00"
@.str.3 = [34 x i8] c"Equialent 12-hour time: %2d:%02d \00"
@str = [3 x i8] c"AM\00"
@str.6 = [3 x i8] c"PM\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %1
%8 = icmp ugt i32 %7, 24
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 59
%11 = select i1 %8, i1 true, i1 %10
%12 = icmp slt i32 %9, 0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %33
16: ; preds = %0
%17 = icmp ugt i32 %7, 11
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = icmp eq i32 %7, 12
br i1 %19, label %25, label %20
20: ; preds = %18
%21 = add nsw i32 %7, -12
store i32 %21, i32* %1
br label %25
22: ; preds = %16
%23 = icmp eq i32 %7, 0
br i1 %23, label %24, label %29
24: ; preds = %22
store i32 12, i32* %1
br label %29
25: ; preds = %18, %20
%26 = phi i32 [ 12, %18 ], [ %21, %20 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %9)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.6, i64 0, i64 0))
br label %33
29: ; preds = %22, %24
%30 = phi i32 [ 12, %24 ], [ %7, %22 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %9)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %25, %29, %14
%34 = phi i32 [ 1, %14 ], [ 0, %29 ], [ 0, %25 ]
ret i32 %34
}