#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *timestr(int t) {
  int hour, min;
  static char str[256];
  char ampm[10], hm[10];
  hour = t / 100;
  min = t % 100;
  if (hour < 0 || hour > 24) {
    fprintf(stderr,
            "timestr: I'm confused, time %d implies hour = %d which is bad!\n",
            t, hour);
    exit(-1);
  }
  if (min < 0 || min > 59) {
    fprintf(
        stderr,
        "timestr: I'm confused, time %d implies minute = %d which is bad!\n", t,
        min);
    exit(-1);
  }
  if (hour == 24 && min > 0) {
    fprintf(stderr,
            "timestr: I'm confused, time %d is beyond 24 hours range!\n", t,
            min);
    exit(-1);
  }
  if (hour < 12) {
    strcpy(ampm, "AM");
  } else {
    strcpy(ampm, "PM");
  }
  if (min == 0) {
    if (hour == 0 || hour == 24) {
      strcpy(ampm, "midnight");
    } else if (hour == 12) {
      strcpy(ampm, "noon");
    }
  }
  if (hour == 0)
    hour = 12;
  if (hour > 12)
    hour -= 12;
  if (min == 0)
    sprintf(hm, "%d", hour);
  else
    sprintf(hm, "%d:%02d", hour, min);
  sprintf(str, "%s %s", hm, ampm);
  return (str);
}


x86 assembly (clang, -O0):
<timestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     117b <timestr+0x3b>
cmpl   $0x18,-0x8(%rbp)
jle    11a0 <timestr+0x60>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11b4 <timestr+0x74>
cmpl   $0x3b,-0xc(%rbp)
jle    11d9 <timestr+0x99>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpl   $0x18,-0x8(%rbp)
jne    1212 <timestr+0xd2>
cmpl   $0x0,-0xc(%rbp)
jle    1212 <timestr+0xd2>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpl   $0xc,-0x8(%rbp)
jge    1231 <timestr+0xf1>
lea    -0x16(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1241 <timestr+0x101>
lea    -0x16(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1298 <timestr+0x158>
cmpl   $0x0,-0x8(%rbp)
je     125f <timestr+0x11f>
cmpl   $0x18,-0x8(%rbp)
jne    1274 <timestr+0x134>
lea    -0x16(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1293 <timestr+0x153>
cmpl   $0xc,-0x8(%rbp)
jne    128e <timestr+0x14e>
lea    -0x16(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1293 <timestr+0x153>
jmp    1298 <timestr+0x158>
cmpl   $0x0,-0x8(%rbp)
jne    12a9 <timestr+0x169>
movl   $0xc,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jle    12bc <timestr+0x17c>
mov    -0x8(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12e0 <timestr+0x1a0>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12f8 <timestr+0x1b8>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x20(%rbp),%rdx
lea    -0x16(%rbp),%rcx
lea    0x2d49(%rip),%rdi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    0x2d34(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x25,%rbx
add    %eax,%ebx
lea    -0x9c4(%r14),%eax
cmp    $0xfffff5d8,%eax
jbe    1289 <timestr+0x149>
imul   $0x64,%ebx,%eax
mov    %r14d,%ebp
sub    %eax,%ebp
cmp    $0x3c,%ebp
jae    12a0 <timestr+0x160>
lea    -0x960(%r14),%r12d
cmp    $0x63,%r12d
ja     119e <timestr+0x5e>
test   %ebp,%ebp
jne    12b2 <timestr+0x172>
cmp    $0x4b0,%r14d
lea    0xf10(%rip),%rax
lea    0xf0c(%rip),%rsi
cmovl  %rax,%rsi
lea    0x16(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x63(%r14),%r15d
test   %ebp,%ebp
je     11f8 <timestr+0xb8>
cmp    $0xc7,%r15d
mov    $0xc,%eax
cmovb  %eax,%ebx
lea    -0xc(%rbx),%edx
cmp    $0xd,%ebx
cmovl  %ebx,%edx
lea    0xeeb(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1257 <timestr+0x117>
lea    0xec3(%rip),%rsi
cmp    $0xc7,%r15d
jb     1222 <timestr+0xe2>
cmp    $0x64,%r12d
jb     1222 <timestr+0xe2>
add    $0xfffffb50,%r14d
cmp    $0x63,%r14d
ja     122c <timestr+0xec>
lea    0xea9(%rip),%rsi
lea    0x16(%rsp),%rdi
call   1030 <strcpy@plt>
cmp    $0xc7,%r15d
mov    $0xc,%eax
cmovb  %eax,%ebx
lea    -0xc(%rbx),%edx
cmp    $0xd,%ebx
cmovl  %ebx,%edx
lea    0xe85(%rip),%rsi
lea    0xc(%rsp),%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x2df2(%rip),%rbx
lea    0xe76(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x16(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
jmp    12c7 <timestr+0x187>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
jmp    12c2 <timestr+0x182>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@timestr.str = internal global [256 x i8] zeroinitializer
@stderr = global i32 0
@.str = [64 x i8] c"timestr: I'm confused, time %d implies hour = %d which is bad!\0A\00"
@.str.1 = [66 x i8] c"timestr: I'm confused, time %d implies minute = %d which is bad!\0A\00"
@.str.2 = [58 x i8] c"timestr: I'm confused, time %d is beyond 24 hours range!\0A\00"
@.str.3 = [3 x i8] c"AM\00"
@.str.4 = [3 x i8] c"PM\00"
@.str.5 = [9 x i8] c"midnight\00"
@.str.6 = [5 x i8] c"noon\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [8 x i8] c"%d:%02d\00"
@.str.9 = [6 x i8] c"%s %s\00"
define i8* @timestr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = sdiv i32 %7, 100
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = srem i32 %9, 100
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 24
br i1 %15, label %16, label %22
16: ; preds = %13, %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %13
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 59
br i1 %27, label %28, label %34
28: ; preds = %25, %22
%29 = load i32, i32* @stderr
%30 = load i32, i32* %2
%31 = load i32, i32* %4
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %25
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 24
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i32, i32* %2
%43 = load i32, i32* %4
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43)
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %37, %34
%47 = load i32, i32* %3
%48 = icmp slt i32 %47, 12
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %55
52: ; preds = %46
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%54 = call i32 @strcpy(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %52, %49
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %75
58: ; preds = %55
%59 = load i32, i32* %3
%60 = icmp eq i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = load i32, i32* %3
%63 = icmp eq i32 %62, 24
br i1 %63, label %64, label %67
64: ; preds = %61, %58
%65 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %74
67: ; preds = %61
%68 = load i32, i32* %3
%69 = icmp eq i32 %68, 12
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%72 = call i32 @strcpy(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %70, %67
br label %74
74: ; preds = %73, %64
br label %75
75: ; preds = %74, %55
%76 = load i32, i32* %3
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %75
store i32 12, i32* %3
br label %79
79: ; preds = %78, %75
%80 = load i32, i32* %3
%81 = icmp sgt i32 %80, 12
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i32, i32* %3
%84 = sub nsw i32 %83, 12
store i32 %84, i32* %3
br label %85
85: ; preds = %82, %79
%86 = load i32, i32* %4
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%90 = load i32, i32* %3
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %90)
br label %97
92: ; preds = %85
%93 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%94 = load i32, i32* %3
%95 = load i32, i32* %4
%96 = call i32 (i8*, i8*, ...) @sprintf(i8* %93, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %94, i32 %95)
br label %97
97: ; preds = %92, %88
%98 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%100 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timestr.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %98, i8* %99)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timestr.str, i64 0, i64 0)
}

LLVM IR (-O2):
@timestr.str = internal global [256 x i8] zeroinitializer
@stderr = global i32 0
@.str = [64 x i8] c"timestr: I'm confused, time %d implies hour = %d which is bad!\0A\00"
@.str.1 = [66 x i8] c"timestr: I'm confused, time %d implies minute = %d which is bad!\0A\00"
@.str.2 = [58 x i8] c"timestr: I'm confused, time %d is beyond 24 hours range!\0A\00"
@.str.3 = [3 x i8] c"AM\00"
@.str.4 = [3 x i8] c"PM\00"
@.str.5 = [9 x i8] c"midnight\00"
@.str.6 = [5 x i8] c"noon\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [8 x i8] c"%d:%02d\00"
@.str.9 = [6 x i8] c"%s %s\00"
define i8* @timestr(i32 %0) {
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = sdiv i32 %0, 100
%7 = srem i32 %0, 100
%8 = add i32 %0, -2500
%9 = icmp ult i32 %8, -2599
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %6)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
%15 = icmp ugt i32 %7, 59
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %7)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %14
%21 = add nsw i32 %0, -2400
%22 = icmp ult i32 %21, 100
%23 = icmp ne i32 %7, 0
%24 = and i1 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %7)
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %20
%30 = icmp slt i32 %0, 1200
%31 = select i1 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%32 = call i32 @strcpy(i8* %4, i8* %31)
%33 = icmp eq i32 %7, 0
%34 = add nsw i32 %0, 99
%35 = icmp ult i32 %34, 199
br i1 %33, label %36, label %50
36: ; preds = %29
%37 = or i1 %35, %22
br i1 %37, label %41, label %38
38: ; preds = %36
%39 = add nsw i32 %0, -1200
%40 = icmp ult i32 %39, 100
br i1 %40, label %41, label %44
41: ; preds = %38, %36
%42 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %36 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), %38 ]
%43 = call i32 @strcpy(i8* %4, i8* %42)
br label %44
44: ; preds = %41, %38
%45 = select i1 %35, i32 12, i32 %6
%46 = icmp sgt i32 %45, 12
%47 = add nsw i32 %45, -12
%48 = select i1 %46, i32 %47, i32 %45
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %48)
br label %56
50: ; preds = %29
%51 = select i1 %35, i32 12, i32 %6
%52 = icmp sgt i32 %51, 12
%53 = add nsw i32 %51, -12
%54 = select i1 %52, i32 %53, i32 %51
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %54, i32 %7)
br label %56
56: ; preds = %50, %44
%57 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @timestr.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %5, i8* %4)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timestr.str, i64 0, i64 0)
}