#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_hour;
  int tm_min;
  int tm_sec;
  int /*<<< orphan*/ member_0;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int, int);
int time_GetUTCTime(char *buf, size_t buf_len) {
  if (buf == NULL || buf[0] == 0 || buf_len < 0) {
    return 0;
  }
  struct timeval tmval;
  struct tm tm_now = {0};
  time_t t_now = 0;
  gettimeofday(&tmval, NULL);
  t_now = tmval.tv_sec;
  localtime_r(&t_now, &tm_now);
  snprintf(buf, buf_len - 1, "%02d-%02d-%02d", tm_now.tm_hour, tm_now.tm_min,
           tm_now.tm_sec);
  return 1;
}


x86 assembly (clang, -O0):
<time_GetUTCTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <time_GetUTCTime+0x36>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1176 <time_GetUTCTime+0x36>
cmpq   $0x0,-0x18(%rbp)
jae    1182 <time_GetUTCTime+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <time_GetUTCTime+0xa3>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movl   $0x0,-0x34(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x34(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xe29(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_GetUTCTime>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     11a0 <time_GetUTCTime+0x70>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11a0 <time_GetUTCTime+0x70>
mov    %rsi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1030 <localtime_r@plt>
add    $0xffffffffffffffff,%r14
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
lea    0xe70(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32 }
@.str = [15 x i8] c"%02d-%02d-%02d\00"
define i32 @time_GetUTCTime(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.timeval
%7 = alloca %struct.tm
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %20, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i64, i64* %5
%19 = icmp ult i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %11, %2
store i32 0, i32* %3
br label %37
21: ; preds = %17
%22 = bitcast %struct.tm* %7 to i8*
store i32 0, i32* %8
%23 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %8
%26 = call i32 @localtime_r(i32* %8, %struct.tm* %7)
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = sub i64 %28, 1
%30 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 @snprintf(i8* %27, i64 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %33, i32 %35)
store i32 1, i32* %3
br label %37
37: ; preds = %21, %20
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
%struct.timeval = type { i32 }
@.str = [15 x i8] c"%02d-%02d-%02d\00"
define i32 @time_GetUTCTime(i8* %0, i64 %1) {
%3 = alloca %struct.tm
%4 = alloca i32
%5 = icmp eq i8* %0, null
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = bitcast %struct.tm* %3 to i8*
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = bitcast i32* %4 to %struct.timeval*
%13 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%14 = call i32 @localtime_r(i32* %4, %struct.tm* %3)
%15 = add i64 %1, -1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%21 = load i32, i32* %20
%22 = call i32 @snprintf(i8* %0, i64 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %21)
br label %23
23: ; preds = %2, %6, %9
%24 = phi i32 [ 1, %9 ], [ 0, %6 ], [ 0, %2 ]
ret i32 %24
}