#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*/ tstring;
typedef int /*<<< orphan*/ flog;

/* Variables and functions */
int /*<<< orphan*/ cmio_jd2y(double const, int *, int *, double *);
double const fabs(double const);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int cmio_log(const double time, const double tstart, const double en[3],
             const double am[3], const int opt[8], char **mem, int lmem[200]) {
  int year = 0, month = 0;
  char flog[38] = {0};
  char tstring[6] = {0};
  if (opt[2] == 0 || opt[2] == 2) {
    strncpy(tstring, mem[0], sizeof(tstring));
    snprintf(flog, sizeof(flog), "(1x,a,f14.1,a,2(a,1p1e12.5))");
  } else if (opt[2] == 1) {
    snprintf(flog, sizeof(flog), "(1x,a,i10,1x,i2,1x,f4.1,2(a,1p1e12.5))");
  } else {
    strncpy(tstring, mem[1], sizeof(tstring));
    snprintf(flog, sizeof(flog), "(1x,a,f14.3,a,2(a,1p1e12.5))");
  }
  double tmp0 = 0.0;
  double tmp1 = 0.0;
  if (en[0]) {
    tmp0 = (en[1] + en[2] - en[0]) / fabs(en[0]);
  }
  if (am[0]) {
    tmp1 = (am[1] + am[2] - am[0]) / fabs(am[0]);
  }
  double t1 = 0.0;
  if (opt[2] == 1) {
    cmio_jd2y(time, &year, &month, &t1);
  } else {
    if (opt[2] == 0) {
      t1 = time;
    }
    if (opt[2] == 2) {
      t1 = time - tstart;
    }
    if (opt[2] == 3) {
      t1 = (time - tstart) / 365.250;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cmio_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x26,%edx
call   1060 <memset@plt>
lea    -0x76(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1060 <memset@plt>
mov    -0x28(%rbp),%rax
cmpl   $0x0,0x8(%rax)
je     11c3 <cmio_log+0x73>
mov    -0x28(%rbp),%rax
cmpl   $0x2,0x8(%rax)
jne    11f2 <cmio_log+0xa2>
lea    -0x76(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x70(%rbp),%rdi
mov    $0x26,%esi
lea    0xe20(%rip),%rdx
call   1050 <snprintf@plt>
jmp    124a <cmio_log+0xfa>
mov    -0x28(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    121a <cmio_log+0xca>
lea    -0x70(%rbp),%rdi
mov    $0x26,%esi
lea    0xe15(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1245 <cmio_log+0xf5>
lea    -0x76(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x70(%rbp),%rdi
mov    $0x26,%esi
lea    0xe0c(%rip),%rdx
call   1050 <snprintf@plt>
jmp    124a <cmio_log+0xfa>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    127d <cmio_log+0x12d>
jp     127d <cmio_log+0x12d>
jmp    12c0 <cmio_log+0x170>
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
addsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1070 <fabs@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12e0 <cmio_log+0x190>
jp     12e0 <cmio_log+0x190>
jmp    1326 <cmio_log+0x1d6>
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
addsd  0x10(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
call   1070 <fabs@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x28(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    135d <cmio_log+0x20d>
movsd  -0x8(%rbp),%xmm0
lea    -0x3c(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1040 <cmio_jd2y@plt>
jmp    13c9 <cmio_log+0x279>
mov    -0x28(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jne    1378 <cmio_log+0x228>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x28(%rbp),%rax
cmpl   $0x2,0x8(%rax)
jne    1398 <cmio_log+0x248>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x28(%rbp),%rax
cmpl   $0x3,0x8(%rax)
jne    13c4 <cmio_log+0x274>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xc48(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    13c9 <cmio_log+0x279>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmio_log>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
movsd  %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x3e(%rsp)
movw   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    0x8(%rdx),%eax
lea    0xe82(%rip),%rbx
test   %eax,%eax
je     1197 <cmio_log+0x67>
cmp    $0x1,%eax
je     11a9 <cmio_log+0x79>
cmp    $0x2,%eax
je     1197 <cmio_log+0x67>
add    $0x8,%rcx
lea    0xead(%rip),%rbx
mov    (%rcx),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1030 <strncpy@plt>
jmp    11b0 <cmio_log+0x80>
lea    0xe6d(%rip),%rbx
lea    0x20(%rsp),%rdi
mov    $0x26,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
movq   $0x0,0x18(%rsp)
cmpl   $0x1,0x8(%r14)
jne    11ec <cmio_log+0xbc>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x18(%rsp),%rdx
movsd  0x10(%rsp),%xmm0
call   1040 <cmio_jd2y@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"(1x,a,f14.1,a,2(a,1p1e12.5))\00"
@.str.1 = [39 x i8] c"(1x,a,i10,1x,i2,1x,f4.1,2(a,1p1e12.5))\00"
@.str.2 = [29 x i8] c"(1x,a,f14.3,a,2(a,1p1e12.5))\00"
define i32 @cmio_log(double %0, double %1, double* %2, double* %3, i32* %4, i8** %5, i32* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32*
%13 = alloca i8**
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca [38 x i8]
%18 = alloca [6 x i8]
%19 = alloca double
%20 = alloca double
%21 = alloca double
store double %0, double* %8
store double %1, double* %9
store double* %2, double** %10
store double* %3, double** %11
store i32* %4, i32** %12
store i8** %5, i8*** %13
store i32* %6, i32** %14
store i32 0, i32* %15
store i32 0, i32* %16
%22 = bitcast [38 x i8]* %17 to i8*
%23 = bitcast [6 x i8]* %18 to i8*
%24 = load i32*, i32** %12
%25 = getelementptr inbounds i32, i32* %24, i64 2
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %7
%29 = load i32*, i32** %12
%30 = getelementptr inbounds i32, i32* %29, i64 2
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %41
33: ; preds = %28, %7
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %18, i64 0, i64 0
%35 = load i8**, i8*** %13
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @strncpy(i8* %34, i8* %37, i32 6)
%39 = getelementptr inbounds [38 x i8], [38 x i8]* %17, i64 0, i64 0
%40 = call i32 @snprintf(i8* %39, i32 38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %58
41: ; preds = %28
%42 = load i32*, i32** %12
%43 = getelementptr inbounds i32, i32* %42, i64 2
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = getelementptr inbounds [38 x i8], [38 x i8]* %17, i64 0, i64 0
%48 = call i32 @snprintf(i8* %47, i32 38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %57
49: ; preds = %41
%50 = getelementptr inbounds [6 x i8], [6 x i8]* %18, i64 0, i64 0
%51 = load i8**, i8*** %13
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @strncpy(i8* %50, i8* %53, i32 6)
%55 = getelementptr inbounds [38 x i8], [38 x i8]* %17, i64 0, i64 0
%56 = call i32 @snprintf(i8* %55, i32 38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %49, %46
br label %58
58: ; preds = %57, %33
store double 0.000000e+00, double* %19
store double 0.000000e+00, double* %20
%59 = load double*, double** %10
%60 = getelementptr inbounds double, double* %59, i64 0
%61 = load double, double* %60
%62 = fcmp une double %61, 0.000000e+00
br i1 %62, label %63, label %80
63: ; preds = %58
%64 = load double*, double** %10
%65 = getelementptr inbounds double, double* %64, i64 1
%66 = load double, double* %65
%67 = load double*, double** %10
%68 = getelementptr inbounds double, double* %67, i64 2
%69 = load double, double* %68
%70 = fadd double %66, %69
%71 = load double*, double** %10
%72 = getelementptr inbounds double, double* %71, i64 0
%73 = load double, double* %72
%74 = fsub double %70, %73
%75 = load double*, double** %10
%76 = getelementptr inbounds double, double* %75, i64 0
%77 = load double, double* %76
%78 = call double @fabs(double %77)
%79 = fdiv double %74, %78
store double %79, double* %19
br label %80
80: ; preds = %63, %58
%81 = load double*, double** %11
%82 = getelementptr inbounds double, double* %81, i64 0
%83 = load double, double* %82
%84 = fcmp une double %83, 0.000000e+00
br i1 %84, label %85, label %102
85: ; preds = %80
%86 = load double*, double** %11
%87 = getelementptr inbounds double, double* %86, i64 1
%88 = load double, double* %87
%89 = load double*, double** %11
%90 = getelementptr inbounds double, double* %89, i64 2
%91 = load double, double* %90
%92 = fadd double %88, %91
%93 = load double*, double** %11
%94 = getelementptr inbounds double, double* %93, i64 0
%95 = load double, double* %94
%96 = fsub double %92, %95
%97 = load double*, double** %11
%98 = getelementptr inbounds double, double* %97, i64 0
%99 = load double, double* %98
%100 = call double @fabs(double %99)
%101 = fdiv double %96, %100
store double %101, double* %20
br label %102
102: ; preds = %85, %80
store double 0.000000e+00, double* %21
%103 = load i32*, i32** %12
%104 = getelementptr inbounds i32, i32* %103, i64 2
%105 = load i32, i32* %104
%106 = icmp eq i32 %105, 1
br i1 %106, label %107, label %110
107: ; preds = %102
%108 = load double, double* %8
%109 = call i32 @cmio_jd2y(double %108, i32* %15, i32* %16, double* %21)
br label %137
110: ; preds = %102
%111 = load i32*, i32** %12
%112 = getelementptr inbounds i32, i32* %111, i64 2
%113 = load i32, i32* %112
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %110
%116 = load double, double* %8
store double %116, double* %21
br label %117
117: ; preds = %115, %110
%118 = load i32*, i32** %12
%119 = getelementptr inbounds i32, i32* %118, i64 2
%120 = load i32, i32* %119
%121 = icmp eq i32 %120, 2
br i1 %121, label %122, label %126
122: ; preds = %117
%123 = load double, double* %8
%124 = load double, double* %9
%125 = fsub double %123, %124
store double %125, double* %21
br label %126
126: ; preds = %122, %117
%127 = load i32*, i32** %12
%128 = getelementptr inbounds i32, i32* %127, i64 2
%129 = load i32, i32* %128
%130 = icmp eq i32 %129, 3
br i1 %130, label %131, label %136
131: ; preds = %126
%132 = load double, double* %8
%133 = load double, double* %9
%134 = fsub double %132, %133
%135 = fdiv double %134, 3.652500e+02
store double %135, double* %21
br label %136
136: ; preds = %131, %126
br label %137
137: ; preds = %136, %107
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"(1x,a,f14.1,a,2(a,1p1e12.5))\00"
@.str.1 = [39 x i8] c"(1x,a,i10,1x,i2,1x,f4.1,2(a,1p1e12.5))\00"
@.str.2 = [29 x i8] c"(1x,a,f14.3,a,2(a,1p1e12.5))\00"
define i32 @cmio_log(double %0, double %1, double* nocapture %2, double* nocapture %3, i32* nocapture %4, i8** nocapture %5, i32* nocapture readnone %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca [38 x i8]
%11 = alloca [6 x i8]
%12 = alloca double
%13 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%14 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%15 = getelementptr inbounds [38 x i8], [38 x i8]* %10, i64 0, i64 0
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%17 = getelementptr inbounds i32, i32* %4, i64 2
%18 = load i32, i32* %17
switch i32 %18, label %19 [
i32 0, label %21
i32 2, label %21
i32 1, label %26
]
19: ; preds = %7
%20 = getelementptr inbounds i8*, i8** %5, i64 1
br label %21
21: ; preds = %7, %7, %19
%22 = phi i8** [ %20, %19 ], [ %5, %7 ], [ %5, %7 ]
%23 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), %19 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %7 ]
%24 = load i8*, i8** %22
%25 = call i32 @strncpy(i8* %16, i8* %24, i32 6)
br label %26
26: ; preds = %21, %7
%27 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), %7 ], [ %23, %21 ]
%28 = call i32 @snprintf(i8* %15, i32 38, i8* %27)
%29 = bitcast double* %12 to i8*
store double 0.000000e+00, double* %12
%30 = load i32, i32* %17
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @cmio_jd2y(double %0, i32* %8, i32* %9, double* %12)
br label %34
34: ; preds = %26, %32
ret i32 0
}