#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*/ sprintf(char *, char *, unsigned short, unsigned char,
                           unsigned char);
char *parseDate(char string[], unsigned short usDate, unsigned char buffer[]) {
  unsigned char month = 0x00, day = 0x00;
  unsigned short year = 0x0000;
  day = (buffer[usDate] & 0x1f);
  year = 0x7bc + ((buffer[usDate + 1] & 0xfd) >> 1);
  month = (buffer[usDate + 1] & 0x01) << 3;
  month = month | ((buffer[usDate] & 0xe0) >> 5);
  sprintf(string, "%d/%d/%d", year, month, day);
  return string;
}


x86 assembly (clang, -O0):
<parseDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
movw   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzwl -0xa(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
and    $0x1f,%eax
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
movzwl -0xa(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xfd,%eax
sar    $0x1,%eax
add    $0x7bc,%eax
mov    %ax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzwl -0xa(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x1,%eax
shl    $0x3,%eax
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
mov    -0x18(%rbp),%rcx
movzwl -0xa(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
and    $0xe0,%ecx
sar    $0x5,%ecx
or     %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%cx
mov    -0x19(%rbp),%al
lea    0xe4b(%rip),%rsi
movzwl %cx,%edx
movzbl %al,%ecx
movzbl -0x1a(%rbp),%r8d
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseDate>:
push   %rbx
mov    %rdi,%rbx
mov    %esi,%eax
movzbl (%rdx,%rax,1),%r8d
movzbl 0x1(%rdx,%rax,1),%eax
lea    0x0(,%rax,8),%ecx
mov    %eax,%edx
shr    %edx
and    $0x7e,%edx
add    $0x7bc,%edx
mov    %r8d,%eax
shr    $0x5,%al
or     %al,%cl
and    $0xf,%cl
movzbl %cl,%ecx
and    $0x1f,%r8d
lea    0xeb3(%rip),%rsi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d/%d/%d\00"
define i8* @parseDate(i8* %0, i16 zeroext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i16
store i8* %0, i8** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
store i8 0, i8* %7
store i8 0, i8* %8
store i16 0, i16* %9
%10 = load i8*, i8** %6
%11 = load i16, i16* %5
%12 = zext i16 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = and i32 %15, 31
%17 = trunc i32 %16 to i8
store i8 %17, i8* %8
%18 = load i8*, i8** %6
%19 = load i16, i16* %5
%20 = zext i16 %19 to i32
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = and i32 %25, 253
%27 = ashr i32 %26, 1
%28 = add nsw i32 1980, %27
%29 = trunc i32 %28 to i16
store i16 %29, i16* %9
%30 = load i8*, i8** %6
%31 = load i16, i16* %5
%32 = zext i16 %31 to i32
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = and i32 %37, 1
%39 = shl i32 %38, 3
%40 = trunc i32 %39 to i8
store i8 %40, i8* %7
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = load i8*, i8** %6
%44 = load i16, i16* %5
%45 = zext i16 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = and i32 %48, 224
%50 = ashr i32 %49, 5
%51 = or i32 %42, %50
%52 = trunc i32 %51 to i8
store i8 %52, i8* %7
%53 = load i8*, i8** %4
%54 = load i16, i16* %9
%55 = load i8, i8* %7
%56 = load i8, i8* %8
%57 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i16 zeroext %54, i8 zeroext %55, i8 zeroext %56)
%58 = load i8*, i8** %4
ret i8* %58
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d/%d/%d\00"
define i8* @parseDate(i8* returned writeonly %0, i16 zeroext %1, i8* nocapture %2) {
%4 = zext i16 %1 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = load i8, i8* %5
%7 = and i8 %6, 31
%8 = add nuw nsw i64 %4, 1
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = load i8, i8* %9
%11 = lshr i8 %10, 1
%12 = and i8 %11, 126
%13 = zext i8 %12 to i16
%14 = add nuw nsw i16 %13, 1980
%15 = shl i8 %10, 3
%16 = and i8 %15, 8
%17 = lshr i8 %6, 5
%18 = or i8 %16, %17
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i16 zeroext %14, i8 zeroext %18, i8 zeroext %7)
ret i8* %0
}