#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*/ assert(int);
int hour_24_to_12(int hour) {
  assert(0 <= hour && hour <= 23);
  if (hour == 0) {
    return 12;
  } else if (hour <= 11) {
    return hour;
  } else if (hour == 12) {
    return 12;
  } else {
    return hour - 12;
  }
}


x86 assembly (clang, -O0):
<hour_24_to_12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x8(%rbp),%ecx
mov    %al,-0x9(%rbp)
jg     1135 <hour_24_to_12+0x25>
cmpl   $0x17,-0x8(%rbp)
setle  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1158 <hour_24_to_12+0x48>
movl   $0xc,-0x4(%rbp)
jmp    118c <hour_24_to_12+0x7c>
cmpl   $0xb,-0x8(%rbp)
jg     116d <hour_24_to_12+0x5d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <hour_24_to_12+0x7c>
cmpl   $0xc,-0x8(%rbp)
jne    1183 <hour_24_to_12+0x73>
movl   $0xc,-0x4(%rbp)
jmp    118c <hour_24_to_12+0x7c>
mov    -0x8(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hour_24_to_12>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0x18,%ebx
setb   %dil
call   1030 <assert@plt>
test   %ebx,%ebx
je     1137 <hour_24_to_12+0x27>
cmp    $0xc,%ebx
jl     113c <hour_24_to_12+0x2c>
lea    -0xc(%rbx),%eax
cmp    $0xc,%ebx
cmove  %ebx,%eax
mov    %eax,%ebx
jmp    113c <hour_24_to_12+0x2c>
mov    $0xc,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hour_24_to_12(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sle i32 0, %4
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 23
br label %9
9: ; preds = %6, %1
%10 = phi i1 [ false, %1 ], [ %8, %6 ]
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 12, i32* %2
br label %28
16: ; preds = %9
%17 = load i32, i32* %3
%18 = icmp sle i32 %17, 11
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32, i32* %3
store i32 %20, i32* %2
br label %28
21: ; preds = %16
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 12
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 12, i32* %2
br label %28
25: ; preds = %21
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 12
store i32 %27, i32* %2
br label %28
28: ; preds = %25, %24, %19, %15
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @hour_24_to_12(i32 %0) {
%2 = icmp ult i32 %0, 24
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i32 %0, 0
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = icmp slt i32 %0, 12
br i1 %7, label %12, label %8
8: ; preds = %6
%9 = icmp eq i32 %0, 12
%10 = add nsw i32 %0, -12
%11 = select i1 %9, i32 12, i32 %10
br label %12
12: ; preds = %8, %6, %1
%13 = phi i32 [ 12, %1 ], [ %0, %6 ], [ %11, %8 ]
ret i32 %13
}