#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 time_t;
struct tm {
  int tm_isdst;
  void *tm_min;
  void *tm_hour;
  void *tm_mday;
  void *tm_mon;
  void *tm_year;
  scalar_t__ tm_yday;
  scalar_t__ tm_wday;
  scalar_t__ tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ LogError(char *, char *);
void *atoi(char *);
int /*<<< orphan*/ localtime_r(int *, struct tm *);
int mktime(struct tm *);
int strlen(char *);
int time(int /*<<< orphan*/ *);
time_t ISO2UNIX(char *timestring) {
  char c, *p;
  struct tm when;
  time_t t;
  t = time(NULL);
  localtime_r(&t, &when);
  when.tm_sec = 0;
  when.tm_wday = 0;
  when.tm_yday = 0;
  when.tm_isdst = -1;
  if (strlen(timestring) != 12) {
    LogError("Wrong time format '%s'\n", timestring);
    return 0;
  }
  p = timestring;
  c = p[4];
  p[4] = '\0';
  when.tm_year = atoi(p) - 1900;
  p[4] = c;
  p += 4;
  c = p[2];
  p[2] = '\0';
  when.tm_mon = atoi(p) - 1;
  p[2] = c;
  p += 2;
  c = p[2];
  p[2] = '\0';
  when.tm_mday = atoi(p);
  p[2] = c;
  p += 2;
  c = p[2];
  p[2] = '\0';
  when.tm_hour = atoi(p);
  p[2] = c;
  p += 2;
  when.tm_min = atoi(p);
  t = mktime(&when);
  if (t == -1) {
    LogError("Failed to convert string '%s'\n", timestring);
    return 0;
  } else {
    return t;
  }
}


x86 assembly (clang, -O0):
<ISO2UNIX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x6c(%rbp)
lea    -0x6c(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   1030 <localtime_r@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xc,%eax
je     11d2 <ISO2UNIX+0x72>
mov    -0x10(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1050 <LogError@plt>
movl   $0x0,-0x4(%rbp)
jmp    12fd <ISO2UNIX+0x19d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
add    $0xfffffffffffff894,%rax
mov    %rax,-0x40(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x50(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x58(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x60(%rbp)
lea    -0x68(%rbp),%rdi
call   1070 <mktime@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xffffffff,-0x6c(%rbp)
jne    12f7 <ISO2UNIX+0x197>
mov    -0x10(%rbp),%rsi
lea    0xd32(%rip),%rdi
call   1050 <LogError@plt>
movl   $0x0,-0x4(%rbp)
jmp    12fd <ISO2UNIX+0x19d>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ISO2UNIX>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rsp)
movq   $0x0,0x50(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xc,%eax
jne    1258 <ISO2UNIX+0xf8>
lea    0x4(%rbx),%r14
mov    0x4(%rbx),%bpl
movb   $0x0,0x4(%rbx)
mov    %rbx,%rdi
call   1080 <atoi@plt>
add    $0xfffffffffffff894,%rax
mov    %rax,0x38(%rsp)
mov    %bpl,0x4(%rbx)
lea    0x6(%rbx),%r15
mov    0x6(%rbx),%bpl
movb   $0x0,0x6(%rbx)
mov    %r14,%rdi
call   1080 <atoi@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,0x30(%rsp)
mov    %bpl,0x6(%rbx)
lea    0x8(%rbx),%r14
mov    0x8(%rbx),%bpl
movb   $0x0,0x8(%rbx)
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %rax,0x28(%rsp)
mov    %bpl,0x8(%rbx)
lea    0xa(%rbx),%r15
mov    0xa(%rbx),%bpl
movb   $0x0,0xa(%rbx)
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %rax,0x20(%rsp)
mov    %bpl,0xa(%rbx)
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %rax,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1070 <mktime@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    1269 <ISO2UNIX+0x109>
lea    0xdc2(%rip),%rdi
jmp    125f <ISO2UNIX+0xff>
lea    0xda1(%rip),%rdi
mov    %rbx,%rsi
call   1050 <LogError@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i8*, i8*, i8*, i8*, i8*, i64, i64, i64 }
@.str = [24 x i8] c"Wrong time format '%s'\0A\00"
@.str.1 = [31 x i8] c"Failed to convert string '%s'\0A\00"
define i32 @ISO2UNIX(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca %struct.tm
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32 @time(i32* null)
store i32 %8, i32* %7
%9 = call i32 @localtime_r(i32* %7, %struct.tm* %6)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 8
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 7
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 6
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i32 -1, i32* %13
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp ne i32 %15, 12
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @LogError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 0, i32* %2
br label %87
20: ; preds = %1
%21 = load i8*, i8** %3
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 4
%24 = load i8, i8* %23
store i8 %24, i8* %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 4
store i8 0, i8* %26
%27 = load i8*, i8** %5
%28 = call i8* @atoi(i8* %27)
%29 = getelementptr i8, i8* %28, i64 -1900
%30 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
store i8* %29, i8** %30
%31 = load i8, i8* %4
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8 %31, i8* %33
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 4
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
store i8 %38, i8* %4
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 2
store i8 0, i8* %40
%41 = load i8*, i8** %5
%42 = call i8* @atoi(i8* %41)
%43 = getelementptr i8, i8* %42, i64 -1
%44 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
store i8* %43, i8** %44
%45 = load i8, i8* %4
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 2
store i8 %45, i8* %47
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 2
store i8* %49, i8** %5
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = load i8, i8* %51
store i8 %52, i8* %4
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 2
store i8 0, i8* %54
%55 = load i8*, i8** %5
%56 = call i8* @atoi(i8* %55)
%57 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
store i8* %56, i8** %57
%58 = load i8, i8* %4
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8 %58, i8* %60
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i64 2
store i8* %62, i8** %5
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 2
%65 = load i8, i8* %64
store i8 %65, i8* %4
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i64 2
store i8 0, i8* %67
%68 = load i8*, i8** %5
%69 = call i8* @atoi(i8* %68)
%70 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
store i8* %69, i8** %70
%71 = load i8, i8* %4
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i64 2
store i8 %71, i8* %73
%74 = load i8*, i8** %5
%75 = getelementptr inbounds i8, i8* %74, i64 2
store i8* %75, i8** %5
%76 = load i8*, i8** %5
%77 = call i8* @atoi(i8* %76)
%78 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
store i8* %77, i8** %78
%79 = call i32 @mktime(%struct.tm* %6)
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %85
82: ; preds = %20
%83 = load i8*, i8** %3
%84 = call i32 @LogError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %83)
store i32 0, i32* %2
br label %87
85: ; preds = %20
%86 = load i32, i32* %7
store i32 %86, i32* %2
br label %87
87: ; preds = %85, %82, %17
%88 = load i32, i32* %2
ret i32 %88
}

LLVM IR (-O2):
%struct.tm = type { i32, i8*, i8*, i8*, i8*, i8*, i64, i64, i64 }
@.str = [24 x i8] c"Wrong time format '%s'\0A\00"
@.str.1 = [31 x i8] c"Failed to convert string '%s'\0A\00"
define i32 @ISO2UNIX(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = bitcast %struct.tm* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call i32 @localtime_r(i32* %3, %struct.tm* %2)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 6
%9 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%10 = bitcast i64* %8 to i8*
store i32 -1, i32* %9
%11 = call i32 @strlen(i8* %0)
%12 = icmp eq i32 %11, 12
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 @LogError(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %40
15: ; preds = %1
%16 = getelementptr inbounds i8, i8* %0, i64 4
%17 = load i8, i8* %16
store i8 0, i8* %16
%18 = call i8* @atoi(i8* %0)
%19 = getelementptr i8, i8* %18, i64 -1900
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i8* %19, i8** %20
store i8 %17, i8* %16
%21 = getelementptr inbounds i8, i8* %0, i64 6
%22 = load i8, i8* %21
store i8 0, i8* %21
%23 = call i8* @atoi(i8* %16)
%24 = getelementptr i8, i8* %23, i64 -1
%25 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i8* %24, i8** %25
store i8 %22, i8* %21
%26 = getelementptr inbounds i8, i8* %0, i64 8
%27 = load i8, i8* %26
store i8 0, i8* %26
%28 = call i8* @atoi(i8* %21)
%29 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i8* %28, i8** %29
store i8 %27, i8* %26
%30 = getelementptr inbounds i8, i8* %0, i64 10
%31 = load i8, i8* %30
store i8 0, i8* %30
%32 = call i8* @atoi(i8* %26)
%33 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i8* %32, i8** %33
store i8 %31, i8* %30
%34 = call i8* @atoi(i8* %30)
%35 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i8* %34, i8** %35
%36 = call i32 @mktime(%struct.tm* %2)
store i32 %36, i32* %3
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %15
%39 = call i32 @LogError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %15, %38, %13
%41 = phi i32 [ 0, %13 ], [ 0, %38 ], [ %36, %15 ]
ret i32 %41
}