#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 */
struct tm {
  int dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
size_t strftime(char *, int, char *, struct tm *);
char *strptime(char *, char *, struct tm *);
int main(int argc, char *argv[]) {
  if (1 < argc) {
    char *strpret, str[24];
    size_t strfret;
    struct tm tm;
    strpret = strptime(argv[1], "%FT%T", &tm);
    if (NULL == strpret) {
      strpret = strptime(argv[1], "%F", &tm);
      if (NULL == strpret) {
        fprintf(stderr, "Invalid date provided: %s", argv[1]);
        return -1;
      }
    }
    strfret = strftime(str, 23, "%s", &tm);
    if (0 == strfret) {
      fprintf(stderr, "Error formatting time for %s", argv[1]);
      return -1;
    }
    printf("%s\n", str);
  } else {
    int ret;
    struct timeval tv;
    ret = gettimeofday(&tv, NULL);
    if (-1 == ret) {
      perror(NULL);
      return -1;
    }
    printf("%lld.%06ld\n", tv.tv_sec, tv.tv_usec);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    126b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6d(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1080 <strptime@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1202 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1080 <strptime@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11fd <main+0x9d>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <main+0x15a>
jmp    1202 <main+0xa2>
lea    -0x30(%rbp),%rdi
mov    $0x17,%esi
lea    0xe0e(%rip),%rdx
lea    -0x40(%rbp),%rcx
call   1060 <strftime@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    1254 <main+0xf4>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde0(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <main+0x15a>
lea    -0x30(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b3 <main+0x153>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x44(%rbp)
mov    $0xffffffff,%eax
cmp    -0x44(%rbp),%eax
jne    129e <main+0x13e>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <main+0x15a>
movslq -0x4c(%rbp),%rsi
mov    -0x50(%rbp),%edx
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
cmp    $0x2,%edi
jl     11d8 <main+0x78>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe88(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1080 <strptime@plt>
test   %rax,%rax
jne    11a1 <main+0x41>
mov    0x8(%rbx),%rdi
lea    0xe74(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1080 <strptime@plt>
test   %rax,%rax
je     120d <main+0xad>
lea    0xe78(%rip),%rdx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x17,%esi
call   1060 <strftime@plt>
test   %rax,%rax
je     1204 <main+0xa4>
lea    0xe78(%rip),%rdi
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    122b <main+0xcb>
xor    %ebx,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1233 <main+0xd3>
movslq 0x14(%rsp),%rsi
mov    0x10(%rsp),%edx
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    122b <main+0xcb>
lea    0xe18(%rip),%rsi
jmp    1214 <main+0xb4>
lea    0xdf5(%rip),%rsi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1070 <perror@plt>
jmp    1226 <main+0xc6>

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%FT%T\00"
@.str.1 = [3 x i8] c"%F\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Invalid date provided: %s\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [29 x i8] c"Error formatting time for %s\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [12 x i8] c"%lld.%06ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [24 x i8]
%8 = alloca i64
%9 = alloca %struct.tm
%10 = alloca i32
%11 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 1, %12
br i1 %13, label %14, label %49
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i8* @strptime(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp eq i8* null, %19
br i1 %20, label %21, label %35
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @strptime(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %9)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = icmp eq i8* null, %26
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %3
br label %64
34: ; preds = %21
br label %35
35: ; preds = %34, %14
%36 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%37 = call i64 @strftime(i8* %36, i32 23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %9)
store i64 %37, i64* %8
%38 = load i64, i64* %8
%39 = icmp eq i64 0, %38
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %44)
store i32 -1, i32* %3
br label %64
46: ; preds = %35
%47 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %47)
br label %63
49: ; preds = %2
%50 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp eq i32 -1, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @perror(i32* null)
store i32 -1, i32* %3
br label %64
55: ; preds = %49
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %59, i32 %61)
br label %63
63: ; preds = %55, %46
store i32 0, i32* %3
br label %64
64: ; preds = %63, %53, %40, %28
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%FT%T\00"
@.str.1 = [3 x i8] c"%F\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Invalid date provided: %s\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [29 x i8] c"Error formatting time for %s\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [12 x i8] c"%lld.%06ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [24 x i8]
%4 = alloca %struct.tm
%5 = alloca %struct.timeval
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%9 = bitcast %struct.tm* %4 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i8* @strptime(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = load i8*, i8** %10
%16 = call i8* @strptime(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %4)
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14, %7
%19 = call i64 @strftime(i8* %8, i32 23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18, %14
%22 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), %18 ]
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = call i32 @fprintf(i32 %23, i8* %22, i8* %24)
br label %42
26: ; preds = %18
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %8)
br label %42
28: ; preds = %2
%29 = bitcast %struct.timeval* %5 to i8*
%30 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%31 = icmp eq i32 %30, -1
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %36, i32 %38)
br label %42
40: ; preds = %28
%41 = tail call i32 @perror(i32* null)
br label %42
42: ; preds = %26, %32, %40, %21
%43 = phi i32 [ -1, %40 ], [ -1, %21 ], [ 0, %32 ], [ 0, %26 ]
ret i32 %43
}