#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 /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int /*<<< orphan*/ tm_mday;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void UTL_GetDicomDate(char *datestr) {
  struct tm *tf;
  time_t loctime;
  loctime = time((time_t *)NULL);
  tf = localtime(&loctime);
  sprintf(datestr, "%04d%02d%02d", (tf->tm_year) + 1900, (tf->tm_mon) + 1,
          tf->tm_mday);
  return;
}


x86 assembly (clang, -O0):
<UTL_GetDicomDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UTL_GetDicomDate>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [13 x i8] c"%04d%02d%02d\00"
define void @UTL_GetDicomDate(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 @time(i32* null)
store i32 %5, i32* %4
%6 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %6, %struct.tm** %3
%7 = load i8*, i8** %2
%8 = load %struct.tm*, %struct.tm** %3
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1900
%12 = load %struct.tm*, %struct.tm** %3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
%16 = load %struct.tm*, %struct.tm** %3
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %15, i32 %18)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [13 x i8] c"%04d%02d%02d\00"
define void @UTL_GetDicomDate(i8* nocapture writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = call %struct.tm* @localtime(i32* %2)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = add nsw i32 %7, 1900
%9 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%13 = load i32, i32* %12
%14 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %13)
ret void
}