#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
double difftime(scalar_t__, scalar_t__);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
char *malloc_or_die(int /*<<< orphan*/, char *, int);
scalar_t__ mktime(struct tm *);
int sscanf(char const *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ *strptime(char *, char const *, struct tm *);
double parse_time(const char *str, const char *fmt) {
  struct tm tm = {0};
  time_t t;
  char *str_dt = malloc_or_die(
      strlen(str),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/ffeast/lmrg/refs/heads/master/src/lmrg.c",
      209);
  if (sscanf(str, "%*[^[][%[^]]", str_dt) != 1) {
    fprintf(stderr, "Could not find \"[...]\" marker in string: %s", str);
    free(str_dt);
    return 0;
  };
  if (strptime(str_dt, fmt, &tm) == NULL) {
    fprintf(stderr, "Could not parse date/time from string: %s", str);
    free(str_dt);
    return 0;
  }
  free(str_dt);
  t = mktime(&tm);
  if (t == (time_t)-1) {
    fprintf(stderr, "Smth is wrong on parsing date/time from string: %s", str);
    exit(EXIT_FAILURE);
  }
  return difftime(t, (time_t)0);
}


x86 assembly (clang, -O0):
<parse_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
lea    0xe2e(%rip),%rsi
mov    $0xd1,%edx
call   10a0 <malloc_or_die@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe94(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     122c <parse_time+0x8c>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d0 <parse_time+0x130>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10c0 <strptime@plt>
cmp    $0x0,%rax
jne    1276 <parse_time+0xd6>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12d0 <parse_time+0x130>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    -0x20(%rbp),%rdi
call   1090 <mktime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    12be <parse_time+0x11e>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <difftime@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
call   1040 <strlen@plt>
lea    0xe4d(%rip),%rsi
mov    %eax,%edi
mov    $0xd1,%edx
call   1090 <malloc_or_die@plt>
mov    %rax,%rbx
lea    0xeba(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1212 <parse_time+0x82>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strptime@plt>
test   %rax,%rax
je     1224 <parse_time+0x94>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x8(%rsp),%rdi
call   1080 <mktime@plt>
cmp    $0xffffffffffffffff,%rax
je     1251 <parse_time+0xc1>
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <difftime@plt>
jmp    1247 <parse_time+0xb7>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
jmp    1234 <parse_time+0xa4>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ffeast/lmrg/refs/heads/master/src/lmrg.c\00"
@.str.1 = [13 x i8] c"%*[^[][%[^]]\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"Could not find \22[...]\22 marker in string: %s\00"
@.str.3 = [42 x i8] c"Could not parse date/time from string: %s\00"
@.str.4 = [51 x i8] c"Smth is wrong on parsing date/time from string: %s\00"
@EXIT_FAILURE = global i32 0
define double @parse_time(i8* %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.tm
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = bitcast %struct.tm* %6 to i8*
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = call i8* @malloc_or_die(i32 %11, i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 209)
store i8* %12, i8** %8
%13 = load i8*, i8** %4
%14 = load i8*, i8** %8
%15 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %8
%22 = call i32 @free(i8* %21)
store double 0.000000e+00, double* %3
br label %49
23: ; preds = %2
%24 = load i8*, i8** %8
%25 = load i8*, i8** %5
%26 = call i32* @strptime(i8* %24, i8* %25, %struct.tm* %6)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
store double 0.000000e+00, double* %3
br label %49
34: ; preds = %23
%35 = load i8*, i8** %8
%36 = call i32 @free(i8* %35)
%37 = call i64 @mktime(%struct.tm* %6)
store i64 %37, i64* %7
%38 = load i64, i64* %7
%39 = icmp eq i64 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %4
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %34
%47 = load i64, i64* %7
%48 = call double @difftime(i64 %47, i64 0)
store double %48, double* %3
br label %49
49: ; preds = %46, %28, %17
%50 = load double, double* %3
ret double %50
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ffeast/lmrg/refs/heads/master/src/lmrg.c\00"
@.str.1 = [13 x i8] c"%*[^[][%[^]]\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"Could not find \22[...]\22 marker in string: %s\00"
@.str.3 = [42 x i8] c"Could not parse date/time from string: %s\00"
@.str.4 = [51 x i8] c"Smth is wrong on parsing date/time from string: %s\00"
@EXIT_FAILURE = global i32 0
define double @parse_time(i8* %0, i8* %1) {
%3 = alloca %struct.tm
%4 = bitcast %struct.tm* %3 to i8*
%5 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
store i32 0, i32* %5
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* @malloc_or_die(i32 %6, i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 209)
%8 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = tail call i32 @free(i8* %7)
br label %32
14: ; preds = %2
%15 = call i32* @strptime(i8* %7, i8* %1, %struct.tm* %3)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%20 = call i32 @free(i8* %7)
br label %32
21: ; preds = %14
%22 = call i32 @free(i8* %7)
%23 = call i64 @mktime(%struct.tm* %3)
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %21
%31 = call double @difftime(i64 %23, i64 0)
br label %32
32: ; preds = %30, %17, %10
%33 = phi double [ 0.000000e+00, %10 ], [ 0.000000e+00, %17 ], [ %31, %30 ]
ret double %33
}