#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *convert(char *hour) {
  int h;
  char t;
  char *nh, *ch;
  nh = malloc(8 * sizeof(char) + 1);
  ch = malloc(2 * sizeof(char) + 1);
  strncpy(nh, hour, 8);
  strncpy(ch, hour, 2);
  h = atoi(ch);
  free(ch);
  t = hour[8];
  if (t == 'A' && h == 12) {
    nh[0] = '0';
    nh[1] = '0';
  } else if (t == 'P' && h != 12) {
    char *nc;
    nc = malloc(2 * sizeof(char) + 1);
    h += 12;
    sprintf(nc, "%d", h);
    nh[0] = nc[0];
    nh[1] = nc[1];
    free(nc);
  }
  return nh;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x41,%eax
jne    11e6 <convert+0x96>
cmpl   $0xc,-0xc(%rbp)
jne    11e6 <convert+0x96>
mov    -0x18(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x30,0x1(%rax)
jmp    124f <convert+0xff>
movsbl -0xd(%rbp),%eax
cmp    $0x50,%eax
jne    124a <convert+0xfa>
cmpl   $0xc,-0xc(%rbp)
je     124a <convert+0xfa>
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xdde(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    124f <convert+0xff>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <strncpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    %rbp,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%al
cmp    $0x41,%al
jne    11bc <convert+0x6c>
cmp    $0xc,%r15d
jne    11bc <convert+0x6c>
movw   $0x3030,(%r14)
jmp    11fd <convert+0xad>
cmp    $0x50,%al
jne    11fd <convert+0xad>
cmp    $0xc,%r15d
je     11fd <convert+0xad>
mov    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
add    $0xc,%r15d
lea    0xe22(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1070 <sprintf@plt>
mov    (%rbx),%al
mov    %al,(%r14)
mov    0x1(%rbx),%al
mov    %al,0x1(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = call i8* @malloc(i32 9)
store i8* %8, i8** %5
%9 = call i8* @malloc(i32 3)
store i8* %9, i8** %6
%10 = load i8*, i8** %5
%11 = load i8*, i8** %2
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 8)
%13 = load i8*, i8** %6
%14 = load i8*, i8** %2
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 2)
%16 = load i8*, i8** %6
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %3
%18 = load i8*, i8** %6
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 8
%22 = load i8, i8* %21
store i8 %22, i8* %4
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 65
br i1 %25, label %26, label %34
26: ; preds = %1
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 12
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 48, i8* %31
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 48, i8* %33
br label %61
34: ; preds = %26, %1
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 80
br i1 %37, label %38, label %60
38: ; preds = %34
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 12
br i1 %40, label %41, label %60
41: ; preds = %38
%42 = call i8* @malloc(i32 3)
store i8* %42, i8** %7
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 12
store i32 %44, i32* %3
%45 = load i8*, i8** %7
%46 = load i32, i32* %3
%47 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 0
store i8 %50, i8* %52
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8 %55, i8* %57
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %41, %38, %34
br label %61
61: ; preds = %60, %29
%62 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @convert(i8* %0) {
%2 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%3 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%4 = tail call i32 @strncpy(i8* %2, i8* %0, i32 8)
%5 = tail call i32 @strncpy(i8* %3, i8* %0, i32 2)
%6 = tail call i32 @atoi(i8* %3)
%7 = tail call i32 @free(i8* %3)
%8 = getelementptr inbounds i8, i8* %0, i64 8
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 65
%11 = icmp eq i32 %6, 12
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %1
store i8 48, i8* %2
%14 = getelementptr inbounds i8, i8* %2, i64 1
store i8 48, i8* %14
br label %28
15: ; preds = %1
%16 = icmp eq i8 %9, 80
%17 = icmp ne i32 %6, 12
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%21 = add nsw i32 %6, 12
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i8, i8* %20
store i8 %23, i8* %2
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %25, i8* %26
%27 = tail call i32 @free(i8* %20)
br label %28
28: ; preds = %15, %19, %13
ret i8* %2
}