#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*/ wchar_t;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
size_t mbstowcs(int /*<<< orphan*/ *, char *, size_t);
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ wcslcpy(int /*<<< orphan*/ *, char *, size_t);
size_t wcstombs(char *, int /*<<< orphan*/ *, int);
void cmd_date_exec(int argc, wchar_t **argv, wchar_t *out, size_t len) {
  (void)argc;
  (void)argv;
  char buf[128];
  char fmt[128];
  time_t t;
  struct tm *tm;
  if (argc > 2) {
    wcslcpy(out, L"<date-bad-arg>", len);
    return;
  }
  if (argc == 2) {
    if (wcstombs(fmt, argv[1], 128) == (size_t)-1) {
      wcslcpy(out, L"<date-bad-charset>", len);
      return;
    }
  } else {
    strlcpy(fmt, "%H:%M:%S", 128);
  }
  t = time(NULL);
  tm = localtime(&t);
  if (tm == NULL) {
    wcslcpy(out, L"<date-bad-time>", len);
    return;
  }
  if (strftime(buf, 128, fmt, tm) == 0) {
    wcslcpy(out, L"<date-bad-format>", len);
    return;
  }
  if (mbstowcs(out, buf, len) == (size_t)-1)
    wcslcpy(out, L"<date-bad-charset>", len);
}


x86 assembly (clang, -O0):
<cmd_date_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    11ad <cmd_date_exec+0x3d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1060 <wcslcpy@plt>
jmp    12cd <cmd_date_exec+0x15d>
cmpl   $0x2,-0x4(%rbp)
jne    11f8 <cmd_date_exec+0x88>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x80,%edx
call   1090 <wcstombs@plt>
cmp    $0xffffffffffffffff,%rax
jne    11f3 <cmd_date_exec+0x83>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1060 <wcslcpy@plt>
jmp    12cd <cmd_date_exec+0x15d>
jmp    1210 <cmd_date_exec+0xa0>
lea    -0x120(%rbp),%rdi
lea    0xf0a(%rip),%rsi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x124(%rbp)
lea    -0x124(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    1259 <cmd_date_exec+0xe9>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1060 <wcslcpy@plt>
jmp    12cd <cmd_date_exec+0x15d>
lea    -0xa0(%rbp),%rdi
lea    -0x120(%rbp),%rdx
mov    -0x130(%rbp),%rcx
mov    $0x80,%esi
call   1080 <strftime@plt>
cmp    $0x0,%rax
jne    129b <cmd_date_exec+0x12b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1060 <wcslcpy@plt>
jmp    12cd <cmd_date_exec+0x15d>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <mbstowcs@plt>
cmp    $0xffffffffffffffff,%rax
jne    12cd <cmd_date_exec+0x15d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd74(%rip),%rsi
call   1060 <wcslcpy@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_date_exec>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
cmp    $0x3,%edi
jl     11a1 <cmd_date_exec+0x31>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
add    $0x118,%rsp
pop    %rbx
pop    %r14
jmp    1060 <wcslcpy@plt>
cmp    $0x2,%edi
jne    11c1 <cmd_date_exec+0x51>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
mov    $0x80,%edx
call   1090 <wcstombs@plt>
cmp    $0xffffffffffffffff,%rax
jne    11d7 <cmd_date_exec+0x67>
jmp    1229 <cmd_date_exec+0xb9>
lea    0xf48(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1232 <cmd_date_exec+0xc2>
lea    0x90(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    $0x80,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
test   %rax,%rax
je     123b <cmd_date_exec+0xcb>
lea    0x90(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <mbstowcs@plt>
cmp    $0xffffffffffffffff,%rax
jne    124d <cmd_date_exec+0xdd>
lea    0xe0c(%rip),%rsi
jmp    1242 <cmd_date_exec+0xd2>
lea    0xe4f(%rip),%rsi
jmp    1242 <cmd_date_exec+0xd2>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <wcslcpy@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [15 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 97, i32 114, i32 103, i32 62, i32 0]
@.str.1 = [19 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 99, i32 104, i32 97, i32 114, i32 115, i32 101, i32 116, i32 62, i32 0]
@.str.2 = [9 x i8] c"%H:%M:%S\00"
@.str.3 = [16 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 116, i32 105, i32 109, i32 101, i32 62, i32 0]
@.str.4 = [18 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 102, i32 111, i32 114, i32 109, i32 97, i32 116, i32 62, i32 0]
define void @cmd_date_exec(i32 %0, i32** %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i64
%9 = alloca [128 x i8]
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca %struct.tm*
store i32 %0, i32* %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
store i64 %3, i64* %8
%13 = load i32, i32* %5
%14 = load i32**, i32*** %6
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32*, i32** %7
%19 = load i64, i64* %8
%20 = call i32 @wcslcpy(i32* %18, i8* bitcast ([15 x i32]* @.str to i8*), i64 %19)
br label %68
21: ; preds = %4
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%26 = load i32**, i32*** %6
%27 = getelementptr inbounds i32*, i32** %26, i64 1
%28 = load i32*, i32** %27
%29 = call i64 @wcstombs(i8* %25, i32* %28, i32 128)
%30 = icmp eq i64 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32*, i32** %7
%33 = load i64, i64* %8
%34 = call i32 @wcslcpy(i32* %32, i8* bitcast ([19 x i32]* @.str.1 to i8*), i64 %33)
br label %68
35: ; preds = %24
br label %39
36: ; preds = %21
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%38 = call i32 @strlcpy(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 128)
br label %39
39: ; preds = %36, %35
%40 = call i32 @time(i32* null)
store i32 %40, i32* %11
%41 = call %struct.tm* @localtime(i32* %11)
store %struct.tm* %41, %struct.tm** %12
%42 = load %struct.tm*, %struct.tm** %12
%43 = icmp eq %struct.tm* %42, null
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32*, i32** %7
%46 = load i64, i64* %8
%47 = call i32 @wcslcpy(i32* %45, i8* bitcast ([16 x i32]* @.str.3 to i8*), i64 %46)
br label %68
48: ; preds = %39
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%51 = load %struct.tm*, %struct.tm** %12
%52 = call i64 @strftime(i8* %49, i32 128, i8* %50, %struct.tm* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = load i32*, i32** %7
%56 = load i64, i64* %8
%57 = call i32 @wcslcpy(i32* %55, i8* bitcast ([18 x i32]* @.str.4 to i8*), i64 %56)
br label %68
58: ; preds = %48
%59 = load i32*, i32** %7
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%61 = load i64, i64* %8
%62 = call i64 @mbstowcs(i32* %59, i8* %60, i64 %61)
%63 = icmp eq i64 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %58
%65 = load i32*, i32** %7
%66 = load i64, i64* %8
%67 = call i32 @wcslcpy(i32* %65, i8* bitcast ([19 x i32]* @.str.1 to i8*), i64 %66)
br label %68
68: ; preds = %17, %31, %44, %54, %64, %58
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [15 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 97, i32 114, i32 103, i32 62, i32 0]
@.str.1 = [19 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 99, i32 104, i32 97, i32 114, i32 115, i32 101, i32 116, i32 62, i32 0]
@.str.2 = [9 x i8] c"%H:%M:%S\00"
@.str.3 = [16 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 116, i32 105, i32 109, i32 101, i32 62, i32 0]
@.str.4 = [18 x i32] [i32 60, i32 100, i32 97, i32 116, i32 101, i32 45, i32 98, i32 97, i32 100, i32 45, i32 102, i32 111, i32 114, i32 109, i32 97, i32 116, i32 62, i32 0]
define void @cmd_date_exec(i32 %0, i32** nocapture %1, i32* %2, i64 %3) {
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = bitcast i32* %7 to i8*
%11 = icmp sgt i32 %0, 2
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @wcslcpy(i32* %2, i8* bitcast ([15 x i32]* @.str to i8*), i64 %3)
br label %41
14: ; preds = %4
%15 = icmp eq i32 %0, 2
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = getelementptr inbounds i32*, i32** %1, i64 1
%18 = load i32*, i32** %17
%19 = call i64 @wcstombs(i8* %9, i32* %18, i32 128)
%20 = icmp eq i64 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @wcslcpy(i32* %2, i8* bitcast ([19 x i32]* @.str.1 to i8*), i64 %3)
br label %41
23: ; preds = %14
%24 = call i32 @strlcpy(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 128)
br label %25
25: ; preds = %16, %23
%26 = call i32 @time(i32* null)
store i32 %26, i32* %7
%27 = call %struct.tm* @localtime(i32* %7)
%28 = icmp eq %struct.tm* %27, null
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @wcslcpy(i32* %2, i8* bitcast ([16 x i32]* @.str.3 to i8*), i64 %3)
br label %41
31: ; preds = %25
%32 = call i64 @strftime(i8* %8, i32 128, i8* %9, %struct.tm* %27)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @wcslcpy(i32* %2, i8* bitcast ([18 x i32]* @.str.4 to i8*), i64 %3)
br label %41
36: ; preds = %31
%37 = call i64 @mbstowcs(i32* %2, i8* %8, i64 %3)
%38 = icmp eq i64 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @wcslcpy(i32* %2, i8* bitcast ([19 x i32]* @.str.1 to i8*), i64 %3)
br label %41
41: ; preds = %36, %39, %34, %29, %21, %12
ret void
}