#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 */
typedef int uint16_t;
struct tm {
  int tm_sec;
  int tm_min;
  int tm_hour;
};

/* Variables and functions */
int htole16(int);
uint16_t tm_struct_to_fat_time(struct tm *time) {
  uint16_t sec = time->tm_sec >> 1;
  sec = sec > 29 ? 29 : sec;
  uint16_t minutes = time->tm_min > 59 ? 59 : time->tm_min;
  uint16_t hour = time->tm_hour > 23 ? 23 : time->tm_hour;
  return htole16((hour << 11) + (minutes << 5) + sec);
}


x86 assembly (clang, -O0):
<tm_struct_to_fat_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1d,-0xc(%rbp)
jle    113f <tm_struct_to_fat_time+0x2f>
mov    $0x1d,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <tm_struct_to_fat_time+0x35>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x3b,0x4(%rax)
jle    1166 <tm_struct_to_fat_time+0x56>
mov    $0x3b,%eax
mov    %eax,-0x1c(%rbp)
jmp    1170 <tm_struct_to_fat_time+0x60>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x17,0x8(%rax)
jle    1191 <tm_struct_to_fat_time+0x81>
mov    $0x17,%eax
mov    %eax,-0x20(%rbp)
jmp    119b <tm_struct_to_fat_time+0x8b>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
shl    $0xb,%edi
mov    -0x10(%rbp),%eax
shl    $0x5,%eax
add    %eax,%edi
add    -0xc(%rbp),%edi
call   1030 <htole16@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_struct_to_fat_time>:
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
sar    %eax
mov    %ecx,%edx
shl    $0x5,%edx
cmp    $0x3c,%ecx
mov    $0x760,%ecx
cmovl  %edx,%ecx
mov    0x8(%rdi),%edx
mov    %edx,%esi
shl    $0xb,%esi
cmp    $0x18,%edx
mov    $0xb800,%edx
cmovl  %esi,%edx
cmp    $0x1d,%eax
mov    $0x1d,%edi
cmovl  %eax,%edi
add    %ecx,%edi
add    %edx,%edi
jmp    1030 <htole16@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @tm_struct_to_fat_time(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %2
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = ashr i32 %8, 1
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 29
br i1 %11, label %12, label %13
12: ; preds = %1
br label %15
13: ; preds = %1
%14 = load i32, i32* %3
br label %15
15: ; preds = %13, %12
%16 = phi i32 [ 29, %12 ], [ %14, %13 ]
store i32 %16, i32* %3
%17 = load %struct.tm*, %struct.tm** %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, 59
br i1 %20, label %21, label %22
21: ; preds = %15
br label %26
22: ; preds = %15
%23 = load %struct.tm*, %struct.tm** %2
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 1
%25 = load i32, i32* %24
br label %26
26: ; preds = %22, %21
%27 = phi i32 [ 59, %21 ], [ %25, %22 ]
store i32 %27, i32* %4
%28 = load %struct.tm*, %struct.tm** %2
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 2
%30 = load i32, i32* %29
%31 = icmp sgt i32 %30, 23
br i1 %31, label %32, label %33
32: ; preds = %26
br label %37
33: ; preds = %26
%34 = load %struct.tm*, %struct.tm** %2
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 2
%36 = load i32, i32* %35
br label %37
37: ; preds = %33, %32
%38 = phi i32 [ 23, %32 ], [ %36, %33 ]
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = shl i32 %39, 11
%41 = load i32, i32* %4
%42 = shl i32 %41, 5
%43 = add nsw i32 %40, %42
%44 = load i32, i32* %3
%45 = add nsw i32 %43, %44
%46 = call i32 @htole16(i32 %45)
ret i32 %46
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i32 @tm_struct_to_fat_time(%struct.tm* nocapture %0) {
%2 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = ashr i32 %3, 1
%5 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, 59
%8 = shl i32 %6, 5
%9 = select i1 %7, i32 1888, i32 %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%11 = load i32, i32* %10
%12 = icmp sgt i32 %11, 23
%13 = shl i32 %11, 11
%14 = select i1 %12, i32 47104, i32 %13
%15 = icmp slt i32 %4, 29
%16 = select i1 %15, i32 %4, i32 29
%17 = add i32 %16, %9
%18 = add i32 %17, %14
%19 = tail call i32 @htole16(i32 %18)
ret i32 %19
}