#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 *, char *);
char toupper(char);
int main(void) {
  int hour, minute;
  char am_pm;
  printf("enter the time (hh-mm (AM/PM)) : ");
  scanf("%d-%d %c", &hour, &minute, &am_pm);
  if (hour < 1 || hour > 12) {
    printf("hours entry is out of range:\n");
    return 0;
  } else if (minute < 0 || minute > 59) {
    printf("minutes entry is out of range: \n");
    return 0;
  } else if ((am_pm = toupper(am_pm)) == 'A' && hour == 12) {
    hour = 0;
  } else if ((am_pm = toupper(am_pm)) == 'P' && hour == 12) {
    hour = 0;
  }
  switch (toupper(am_pm)) {
  case 'P':
    hour += 12;
    break;
  case 'A':
    break;
  default:
    printf("Invalid AM/PM entry\n");
    return 0;
  }
  printf("equivalent 24 hour time: %2d:%.2d\n", hour, minute);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1050 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     1179 <main+0x49>
cmpl   $0xc,-0x8(%rbp)
jle    1193 <main+0x63>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <main+0x16d>
cmpl   $0x0,-0xc(%rbp)
jl     11a7 <main+0x77>
cmpl   $0x3b,-0xc(%rbp)
jle    11c1 <main+0x91>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <main+0x16d>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0x41,%eax
jne    11ef <main+0xbf>
cmpl   $0xc,-0x8(%rbp)
jne    11ef <main+0xbf>
movl   $0x0,-0x8(%rbp)
jmp    121d <main+0xed>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0x50,%eax
jne    1218 <main+0xe8>
cmpl   $0xc,-0x8(%rbp)
jne    1218 <main+0xe8>
movl   $0x0,-0x8(%rbp)
jmp    121d <main+0xed>
jmp    1222 <main+0xf2>
jmp    1227 <main+0xf7>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
sub    $0x41,%eax
je     1263 <main+0x133>
jmp    1244 <main+0x114>
mov    -0x14(%rbp),%eax
sub    $0x50,%eax
jne    1268 <main+0x138>
jmp    1255 <main+0x125>
mov    -0x8(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x8(%rbp)
jmp    1282 <main+0x152>
jmp    1282 <main+0x152>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <main+0x16d>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec9(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0xf(%rsp),%rcx
call   1060 <scanf@plt>
mov    0x10(%rsp),%eax
add    $0xfffffff3,%eax
cmp    $0xfffffff3,%eax
ja     1185 <main+0x45>
lea    0xf02(%rip),%rdi
jmp    121f <main+0xdf>
cmpl   $0x3c,0x14(%rsp)
jb     1198 <main+0x58>
lea    0xecf(%rip),%rdi
jmp    121f <main+0xdf>
movsbl 0xf(%rsp),%edi
call   1030 <toupper@plt>
mov    %al,0xf(%rsp)
cmp    $0x41,%al
jne    11bd <main+0x7d>
cmpl   $0xc,0x10(%rsp)
jne    11bd <main+0x7d>
movl   $0x0,0x10(%rsp)
mov    $0x41,%al
jmp    11de <main+0x9e>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,0xf(%rsp)
cmp    $0x50,%al
jne    11de <main+0x9e>
cmpl   $0xc,0x10(%rsp)
jne    11de <main+0x9e>
movl   $0x0,0x10(%rsp)
mov    $0x50,%al
movsbl %al,%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x50,%eax
je     11f9 <main+0xb9>
cmp    $0x41,%eax
jne    1218 <main+0xd8>
mov    0x10(%rsp),%esi
jmp    1204 <main+0xc4>
mov    0x10(%rsp),%esi
add    $0xc,%esi
mov    %esi,0x10(%rsp)
mov    0x14(%rsp),%edx
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1224 <main+0xe4>
lea    0xe2f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"enter the time (hh-mm (AM/PM)) : \00"
@.str.1 = [9 x i8] c"%d-%d %c\00"
@.str.2 = [30 x i8] c"hours entry is out of range:\0A\00"
@.str.3 = [33 x i8] c"minutes entry is out of range: \0A\00"
@.str.4 = [21 x i8] c"Invalid AM/PM entry\0A\00"
@.str.5 = [35 x i8] c"equivalent 24 hour time: %2d:%.2d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i8* %4)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 12
br i1 %11, label %12, label %14
12: ; preds = %9, %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %57
14: ; preds = %9
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 59
br i1 %19, label %20, label %22
20: ; preds = %17, %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %57
22: ; preds = %17
%23 = load i8, i8* %4
%24 = call signext i8 @toupper(i8 signext %23)
store i8 %24, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 65
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 12
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %2
br label %41
31: ; preds = %27, %22
%32 = load i8, i8* %4
%33 = call signext i8 @toupper(i8 signext %32)
store i8 %33, i8* %4
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 80
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, 12
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 0, i32* %2
br label %40
40: ; preds = %39, %36, %31
br label %41
41: ; preds = %40, %30
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = load i8, i8* %4
%45 = call signext i8 @toupper(i8 signext %44)
%46 = sext i8 %45 to i32
switch i32 %46, label %51 [
i32 80, label %47
i32 65, label %50
]
47: ; preds = %43
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 12
store i32 %49, i32* %2
br label %53
50: ; preds = %43
br label %53
51: ; preds = %43
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %57
53: ; preds = %50, %47
%54 = load i32, i32* %2
%55 = load i32, i32* %3
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %54, i32 %55)
store i32 0, i32* %1
br label %57
57: ; preds = %53, %51, %20, %12
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [34 x i8] c"enter the time (hh-mm (AM/PM)) : \00"
@.str.1 = [9 x i8] c"%d-%d %c\00"
@.str.5 = [35 x i8] c"equivalent 24 hour time: %2d:%.2d\0A\00"
@str = [20 x i8] c"Invalid AM/PM entry\00"
@str.6 = [32 x i8] c"minutes entry is out of range: \00"
@str.7 = [29 x i8] c"hours entry is out of range:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i8* %3)
%8 = load i32, i32* %1
%9 = add i32 %8, -13
%10 = icmp ult i32 %9, -12
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
br label %48
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp ugt i32 %14, 59
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
br label %48
18: ; preds = %13
%19 = load i8, i8* %3
%20 = call signext i8 @toupper(i8 signext %19)
store i8 %20, i8* %3
%21 = icmp eq i8 %20, 65
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, 12
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 0, i32* %1
br label %33
26: ; preds = %18
%27 = call signext i8 @toupper(i8 signext %20)
store i8 %27, i8* %3
%28 = icmp eq i8 %27, 80
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 12
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 0, i32* %1
br label %33
33: ; preds = %26, %32, %25
%34 = phi i8 [ %27, %26 ], [ 80, %32 ], [ 65, %25 ]
%35 = call signext i8 @toupper(i8 signext %34)
%36 = sext i8 %35 to i32
switch i32 %36, label %42 [
i32 80, label %39
i32 65, label %37
]
37: ; preds = %33
%38 = load i32, i32* %1
br label %44
39: ; preds = %33
%40 = load i32, i32* %1
%41 = add nsw i32 %40, 12
store i32 %41, i32* %1
br label %44
42: ; preds = %33
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %48
44: ; preds = %37, %39
%45 = phi i32 [ %38, %37 ], [ %41, %39 ]
%46 = load i32, i32* %2
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %45, i32 %46)
br label %48
48: ; preds = %44, %42, %16, %11
ret i32 0
}