#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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
char toupper(char);
int main() {
  char time[1024];
  char *hour, *minute, *rest;
  char second[8];
  char pm[8];
  bool is_pm = false;
  int h;
  char hh[8];
  int len;
  scanf("%s", time);
  len = strlen(time);
  pm[0] = time[len - 2];
  pm[1] = time[len - 1];
  pm[0] = toupper(pm[0]);
  pm[1] = toupper(pm[1]);
  pm[2] = '\0';
  if (strcmp(pm, "PM") == 0)
    is_pm = true;
  hour = strtok(time, ":");
  minute = strtok(NULL, ":");
  if (minute != NULL)
    *(minute + 2) = '\0';
  rest = strtok(NULL, ":");
  if (rest == NULL)
    second[0] = '\0';
  else
    strncpy(second, rest, 2);
  if (is_pm) {
    sscanf(hour, "%d", &h);
    h = h + 12;
    if (h >= 24)
      h = h - 12;
    sprintf(hh, "%d", h);
  } else
    strcpy(hh, hour);
  printf("%s", hh);
  if (minute)
    printf(":%s", minute);
  if (second[0] != '\0')
    printf(":%s", second);
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x43c(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x44c(%rbp),%eax
sub    $0x2,%eax
cltq
mov    -0x410(%rbp,%rax,1),%al
mov    %al,-0x438(%rbp)
mov    -0x44c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x410(%rbp,%rax,1),%al
mov    %al,-0x437(%rbp)
movsbl -0x438(%rbp),%edi
call   1050 <toupper@plt>
mov    %al,-0x438(%rbp)
movsbl -0x437(%rbp),%edi
call   1050 <toupper@plt>
mov    %al,-0x437(%rbp)
movb   $0x0,-0x436(%rbp)
lea    -0x438(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1263 <main+0xc3>
movl   $0x1,-0x43c(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x418(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7b(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     12ad <main+0x10d>
mov    -0x420(%rbp),%rax
movb   $0x0,0x2(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd4b(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    12de <main+0x13e>
movb   $0x0,-0x430(%rbp)
jmp    12f6 <main+0x156>
lea    -0x430(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x43c(%rbp)
je     1366 <main+0x1c6>
mov    -0x418(%rbp),%rdi
lea    0xcf4(%rip),%rsi
lea    -0x440(%rbp),%rdx
call   1090 <sscanf@plt>
mov    -0x440(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x440(%rbp)
cmpl   $0x18,-0x440(%rbp)
jl     1348 <main+0x1a8>
mov    -0x440(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x440(%rbp)
lea    -0x448(%rbp),%rdi
mov    -0x440(%rbp),%edx
lea    0xca9(%rip),%rsi
call   10c0 <sprintf@plt>
jmp    1379 <main+0x1d9>
lea    -0x448(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x448(%rbp),%rsi
lea    0xc82(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x420(%rbp)
je     13b1 <main+0x211>
mov    -0x420(%rbp),%rsi
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsbl -0x430(%rbp),%eax
cmp    $0x0,%eax
je     13d6 <main+0x236>
lea    -0x430(%rbp),%rsi
lea    0xc39(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x428,%rsp
lea    0xe45(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movsbl -0x2(%rax,%rbx,1),%edi
movsbl -0x1(%rax,%rbx,1),%ebp
call   1060 <toupper@plt>
mov    %al,0x8(%rsp)
mov    %ebp,%edi
call   1060 <toupper@plt>
mov    %al,0x9(%rsp)
movb   $0x0,0xa(%rsp)
lea    0xdfb(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1090 <strcmp@plt>
mov    %rax,%r15
lea    0xdea(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     123d <main+0x8d>
movb   $0x0,0x2(%rbx)
lea    0xdbf(%rip),%rsi
xor    %edi,%edi
call   10c0 <strtok@plt>
test   %rax,%rax
je     1276 <main+0xc6>
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
test   %r15,%r15
je     1280 <main+0xd0>
lea    0x18(%rsp),%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
jmp    12b5 <main+0x105>
movb   $0x0,0x10(%rsp)
test   %r15,%r15
jne    1267 <main+0xb7>
lea    0xd7e(%rip),%rbp
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <sscanf@plt>
mov    0x4(%rsp),%eax
lea    0xc(%rax),%edx
cmp    $0xc,%eax
cmovge %eax,%edx
mov    %edx,0x4(%rsp)
lea    0x18(%rsp),%rdi
mov    %rbp,%rsi
call   10d0 <sprintf@plt>
lea    0xd4d(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
test   %rbx,%rbx
je     12de <main+0x12e>
lea    0xd34(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
cmpb   $0x0,0x10(%rsp)
je     12f8 <main+0x148>
lea    0xd1c(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"PM\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c":%s\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [8 x i8]
%7 = alloca [8 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [8 x i8]
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = sub nsw i32 %16, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
store i8 %20, i8* %21
%22 = load i32, i32* %11
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
store i8 %26, i8* %27
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = call signext i8 @toupper(i8 signext %29)
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
store i8 %30, i8* %31
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
%33 = load i8, i8* %32
%34 = call signext i8 @toupper(i8 signext %33)
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
store i8 %34, i8* %35
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 2
store i8 0, i8* %36
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %0
store i32 1, i32* %8
br label %41
41: ; preds = %40, %0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%43 = call i8* @strtok(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %43, i8** %3
%44 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %44, i8** %4
%45 = load i8*, i8** %4
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 2
store i8 0, i8* %49
br label %50
50: ; preds = %47, %41
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %51, i8** %5
%52 = load i8*, i8** %5
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
store i8 0, i8* %55
br label %60
56: ; preds = %50
%57 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%58 = load i8*, i8** %5
%59 = call i32 @strncpy(i8* %57, i8* %58, i32 2)
br label %60
60: ; preds = %56, %54
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %77
63: ; preds = %60
%64 = load i8*, i8** %3
%65 = call i32 @sscanf(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 12
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp sge i32 %68, 24
br i1 %69, label %70, label %73
70: ; preds = %63
%71 = load i32, i32* %9
%72 = sub nsw i32 %71, 12
store i32 %72, i32* %9
br label %73
73: ; preds = %70, %63
%74 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%75 = load i32, i32* %9
%76 = call i32 @sprintf(i8* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %75)
br label %81
77: ; preds = %60
%78 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%79 = load i8*, i8** %3
%80 = call i32 @strcpy(i8* %78, i8* %79)
br label %81
81: ; preds = %77, %73
%82 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %82)
%84 = load i8*, i8** %4
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i8*, i8** %4
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %86, %81
%90 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %89
%95 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %95)
br label %97
97: ; preds = %94, %89
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%99 = load i32, i32* %1
ret i32 %99
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"PM\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c":%s\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%12 = call i32 @strlen(i8* %6)
%13 = add nsw i32 %12, -2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = add nsw i32 %12, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%22 = call signext i8 @toupper(i8 signext %16)
store i8 %22, i8* %8
%23 = call signext i8 @toupper(i8 signext %20)
store i8 %23, i8* %21
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
store i8 0, i8* %24
%25 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %0
%31 = getelementptr inbounds i8, i8* %28, i64 2
store i8 0, i8* %31
br label %32
32: ; preds = %30, %0
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %32
store i8 0, i8* %7
br label %38
36: ; preds = %32
%37 = call i32 @strncpy(i8* %7, i8* %33, i32 2)
br label %38
38: ; preds = %36, %35
br i1 %26, label %39, label %46
39: ; preds = %38
%40 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 12
%43 = icmp sgt i32 %41, 11
%44 = select i1 %43, i32 %41, i32 %42
store i32 %44, i32* %4
%45 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %48
46: ; preds = %38
%47 = call i32 @strcpy(i8* %10, i8* %27)
br label %48
48: ; preds = %46, %39
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
br i1 %29, label %52, label %50
50: ; preds = %48
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %52
52: ; preds = %50, %48
%53 = load i8, i8* %7
%54 = icmp eq i8 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
br label %57
57: ; preds = %55, %52
%58 = call i32 @putchar(i32 10)
ret i32 0
}