#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 scalar_t__ time_t;
struct tm {
  char tm_sec;
  int tm_min;
  int tm_hour;
  int tm_yday;
  int tm_wday;
};
struct timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
char *cm11a_encodetime(char *buf) {
  time_t t;
  struct timeval tv;
  struct tm tm;
  gettimeofday(&tv, 0);
  t = (time_t)tv.tv_sec;
  localtime_r(&t, &tm);
  buf[0] = 0x9b;
  buf[1] = tm.tm_sec;
  buf[2] = tm.tm_min + (((tm.tm_hour) & 0x01) * 60);
  buf[3] = tm.tm_hour >> 1;
  buf[4] = tm.tm_yday & 0xff;
  buf[5] = ((tm.tm_yday & 0x100) >> 1) & 0xff;
  buf[5] |= (1 << tm.tm_wday);
  buf[6] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<cm11a_encodetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rax
movb   $0x9b,(%rax)
mov    -0x30(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%ecx
and    $0x1,%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x28(%rbp),%eax
sar    $0x1,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x24(%rbp),%eax
and    $0x100,%eax
sar    $0x1,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%rax
movsbl 0x5(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x5(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm11a_encodetime>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x20(%rsp),%rax
mov    %rax,0x28(%rsp)
lea    0x28(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
movb   $0x9b,(%rbx)
mov    0x8(%rsp),%al
mov    %al,0x1(%rbx)
mov    0x10(%rsp),%eax
mov    %eax,%ecx
and    $0x1,%ecx
imul   $0x3c,%ecx,%ecx
add    0xc(%rsp),%ecx
mov    %cl,0x2(%rbx)
shr    %eax
mov    %al,0x3(%rbx)
mov    0x14(%rsp),%eax
mov    %al,0x4(%rbx)
shr    %eax
mov    0x18(%rsp),%cl
mov    $0x1,%edx
shl    %cl,%edx
and    $0x80,%al
or     %al,%dl
mov    %dl,0x5(%rbx)
movb   $0x0,0x6(%rbx)
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.tm = type { i8, i32, i32, i32, i32 }
define i8* @cm11a_encodetime(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.timeval
%5 = alloca %struct.tm
store i8* %0, i8** %2
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%8 = load i64, i64* %7
store i64 %8, i64* %3
%9 = call i32 @localtime_r(i64* %3, %struct.tm* %5)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 -101, i8* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%13 = load i8, i8* %12
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %13, i8* %15
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%19 = load i32, i32* %18
%20 = and i32 %19, 1
%21 = mul nsw i32 %20, 60
%22 = add nsw i32 %17, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8 %23, i8* %25
%26 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%27 = load i32, i32* %26
%28 = ashr i32 %27, 1
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i64 3
store i8 %29, i8* %31
%32 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%33 = load i32, i32* %32
%34 = and i32 %33, 255
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 4
store i8 %35, i8* %37
%38 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
%39 = load i32, i32* %38
%40 = and i32 %39, 256
%41 = ashr i32 %40, 1
%42 = and i32 %41, 255
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 5
store i8 %43, i8* %45
%46 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
%47 = load i32, i32* %46
%48 = shl i32 1, %47
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i64 5
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = or i32 %52, %48
%54 = trunc i32 %53 to i8
store i8 %54, i8* %50
%55 = load i8*, i8** %2
%56 = getelementptr inbounds i8, i8* %55, i64 6
store i8 0, i8* %56
%57 = load i8*, i8** %2
ret i8* %57
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.tm = type { i8, i32, i32, i32, i32 }
define i8* @cm11a_encodetime(i8* returned writeonly %0) {
%2 = alloca i64
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = bitcast i64* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
store i64 %10, i64* %2
%11 = call i32 @localtime_r(i64* %2, %struct.tm* %4)
store i8 -101, i8* %0
%12 = load i8, i8* %7
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %12, i8* %13
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%17 = load i32, i32* %16
%18 = and i32 %17, 1
%19 = mul nuw nsw i32 %18, 60
%20 = add nsw i32 %19, %15
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %21, i8* %22
%23 = lshr i32 %17, 1
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %24, i8* %25
%26 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%27 = load i32, i32* %26
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %28, i8* %29
%30 = lshr i32 %27, 1
%31 = trunc i32 %30 to i8
%32 = and i8 %31, -128
%33 = getelementptr inbounds i8, i8* %0, i64 5
%34 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%35 = load i32, i32* %34
%36 = shl nuw i32 1, %35
%37 = trunc i32 %36 to i8
%38 = or i8 %32, %37
store i8 %38, i8* %33
%39 = getelementptr inbounds i8, i8* %0, i64 6
store i8 0, i8* %39
ret i8* %0
}