#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 *);
int toupper(char);
int main(void) {
  int hour, mins;
  char ampm;
  printf("Enter a 12-hour time: ");
  scanf("%2d:%2d %1c", &hour, &mins, &ampm);
  switch (toupper(ampm)) {
  case 'P':
    hour += 12;
    break;
  case 'A':
    break;
  default:
    printf("Invalid input!\n");
    return 0;
  }
  printf("Equivalent 24-hour time is: %2d:%2d\n", hour, mins);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1050 <scanf@plt>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x41,%eax
je     11a0 <main+0x70>
jmp    1181 <main+0x51>
mov    -0x14(%rbp),%eax
sub    $0x50,%eax
jne    11a5 <main+0x75>
jmp    1192 <main+0x62>
mov    -0x8(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x8(%rbp)
jmp    11bf <main+0x8f>
jmp    11bf <main+0x8f>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <main+0xaa>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe67(%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    0xebe(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0xf(%rsp),%rcx
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%edi
call   1030 <toupper@plt>
cmp    $0x50,%eax
je     1187 <main+0x47>
cmp    $0x41,%eax
jne    11a6 <main+0x66>
mov    0x10(%rsp),%esi
jmp    1192 <main+0x52>
mov    0x10(%rsp),%esi
add    $0xc,%esi
mov    %esi,0x10(%rsp)
mov    0x14(%rsp),%edx
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b2 <main+0x72>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Enter a 12-hour time: \00"
@.str.1 = [12 x i8] c"%2d:%2d %1c\00"
@.str.2 = [16 x i8] c"Invalid input!\0A\00"
@.str.3 = [37 x i8] c"Equivalent 24-hour time is: %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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i8* %4)
%7 = load i8, i8* %4
%8 = call i32 @toupper(i8 signext %7)
switch i32 %8, label %13 [
i32 80, label %9
i32 65, label %12
]
9: ; preds = %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 12
store i32 %11, i32* %2
br label %15
12: ; preds = %0
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %19
15: ; preds = %12, %9
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17)
store i32 0, i32* %1
br label %19
19: ; preds = %15, %13
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [23 x i8] c"Enter a 12-hour time: \00"
@.str.1 = [12 x i8] c"%2d:%2d %1c\00"
@.str.3 = [37 x i8] c"Equivalent 24-hour time is: %2d:%2d\0A\00"
@str = [15 x i8] c"Invalid input!\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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i8* %3)
%8 = load i8, i8* %3
%9 = call i32 @toupper(i8 signext %8)
switch i32 %9, label %15 [
i32 80, label %12
i32 65, label %10
]
10: ; preds = %0
%11 = load i32, i32* %1
br label %17
12: ; preds = %0
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 12
store i32 %14, i32* %1
br label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %21
17: ; preds = %10, %12
%18 = phi i32 [ %11, %10 ], [ %14, %12 ]
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %17, %15
ret i32 0
}