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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *, scalar_t__, double, double);
scalar_t__ round(double);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strptime(char *, char *, struct tm *);
double strtod(char *, char **);
scalar_t__ timegm(struct tm *);
int cvt_a_date(char *s) {
  char *leftover;
  char *z = "?";
  struct tm tm = {0};
  time_t seconds;
  double fraction = 0.0;
  double fulltime;
  double back;
  int res = 0;
  intmax_t fixedscaled;
  leftover = strptime(s, "%FT%T", &tm);
  seconds = timegm(&tm);
  if (leftover != NULL)
    fraction = strtod(leftover, &z);
  if (0 != strcmp(z, "Z") || seconds <= 0 || fraction < 0.0 ||
      fraction >= 1.0) {
    res = 1;
    fprintf(stderr, "problem converting %s\n", s);
  } else {
    fulltime = (((double)seconds) + fraction);
    fixedscaled = (intmax_t)round(fulltime * (double)(1U << 12));
    back = (double)fixedscaled / 4096.0;
    printf("%s\t%012jX\t%f\t%f\n", s, fixedscaled, fulltime, back);
  }
  return (res);
}


x86 assembly (clang, -O0):
<cvt_a_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <strptime@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <timegm@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f8 <cvt_a_date+0x78>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1246 <cvt_a_date+0xc6>
cmpq   $0x0,-0x28(%rbp)
jle    1246 <cvt_a_date+0xc6>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
ja     1246 <cvt_a_date+0xc6>
movsd  -0x30(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     126b <cvt_a_date+0xeb>
movl   $0x1,-0x44(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb9(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12c6 <cvt_a_date+0x146>
cvtsi2sdq -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xd85(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1090 <round@plt>
mov    %rax,-0x50(%rbp)
cvtsi2sdq -0x50(%rbp),%xmm0
movsd  0xd69(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x50(%rbp),%rdx
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvt_a_date>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe93(%rip),%r12
mov    %r12,0x10(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe81(%rip),%rsi
lea    0x8(%rsp),%r15
mov    %r15,%rdx
call   1090 <strptime@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <timegm@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     11d2 <cvt_a_date+0x62>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strtod@plt>
movsd  %xmm0,(%rsp)
mov    0x10(%rsp),%r12
jmp    11db <cvt_a_date+0x6b>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe3e(%rip),%rsi
mov    %r12,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
movsd  (%rsp),%xmm1
jne    125a <cvt_a_date+0xea>
test   %r15,%r15
jle    125a <cvt_a_date+0xea>
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
ja     125a <cvt_a_date+0xea>
ucomisd 0xdf5(%rip),%xmm1
jae    125a <cvt_a_date+0xea>
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xde2(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1080 <round@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  0xdd1(%rip),%xmm1
lea    0xdf3(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
movsd  (%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1277 <cvt_a_date+0x107>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [2 x i8] c"?\00"
@.str.1 = [6 x i8] c"%FT%T\00"
@.str.2 = [2 x i8] c"Z\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"problem converting %s\0A\00"
@.str.4 = [17 x i8] c"%s\09%012jX\09%f\09%f\0A\00"
define i32 @cvt_a_date(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.tm
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
%12 = bitcast %struct.tm* %5 to i8*
store double 0.000000e+00, double* %7
store i32 0, i32* %10
%13 = load i8*, i8** %2
%14 = call i8* @strptime(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %5)
store i8* %14, i8** %3
%15 = call i64 @timegm(%struct.tm* %5)
store i64 %15, i64* %6
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = call double @strtod(i8* %19, i8** %4)
store double %20, double* %7
br label %21
21: ; preds = %18, %1
%22 = load i8*, i8** %4
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 0, %23
br i1 %24, label %34, label %25
25: ; preds = %21
%26 = load i64, i64* %6
%27 = icmp sle i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = load double, double* %7
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load double, double* %7
%33 = fcmp oge double %32, 1.000000e+00
br i1 %33, label %34, label %38
34: ; preds = %31, %28, %25, %21
store i32 1, i32* %10
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %2
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %54
38: ; preds = %31
%39 = load i64, i64* %6
%40 = sitofp i64 %39 to double
%41 = load double, double* %7
%42 = fadd double %40, %41
store double %42, double* %8
%43 = load double, double* %8
%44 = fmul double %43, 4.096000e+03
%45 = call i64 @round(double %44)
store i64 %45, i64* %11
%46 = load i64, i64* %11
%47 = sitofp i64 %46 to double
%48 = fdiv double %47, 4.096000e+03
store double %48, double* %9
%49 = load i8*, i8** %2
%50 = load i64, i64* %11
%51 = load double, double* %8
%52 = load double, double* %9
%53 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %49, i64 %50, double %51, double %52)
br label %54
54: ; preds = %38, %34
%55 = load i32, i32* %10
ret i32 %55
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [2 x i8] c"?\00"
@.str.1 = [6 x i8] c"%FT%T\00"
@.str.2 = [2 x i8] c"Z\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"problem converting %s\0A\00"
@.str.4 = [17 x i8] c"%s\09%012jX\09%f\09%f\0A\00"
define i32 @cvt_a_date(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = bitcast i8** %2 to i8*
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = bitcast %struct.tm* %3 to i8*
%6 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 0, i32* %6
%7 = call i8* @strptime(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
%8 = call i64 @timegm(%struct.tm* %3)
%9 = icmp eq i8* %7, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call double @strtod(i8* %7, i8** %2)
%12 = load i8*, i8** %2
br label %13
13: ; preds = %10, %1
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ]
%15 = phi double [ %11, %10 ], [ 0.000000e+00, %1 ]
%16 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
%18 = icmp slt i64 %8, 1
%19 = select i1 %17, i1 true, i1 %18
%20 = fcmp olt double %15, 0.000000e+00
%21 = select i1 %19, i1 true, i1 %20
%22 = fcmp oge double %15, 1.000000e+00
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %35
27: ; preds = %13
%28 = sitofp i64 %8 to double
%29 = fadd double %15, %28
%30 = fmul double %29, 4.096000e+03
%31 = call i64 @round(double %30)
%32 = sitofp i64 %31 to double
%33 = fmul double %32, 0x3F30000000000000
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %0, i64 %31, double %29, double %33)
br label %35
35: ; preds = %27, %24
%36 = phi i32 [ 1, %24 ], [ 0, %27 ]
ret i32 %36
}