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

/* Variables and functions */
int /*<<< orphan*/ LC_TIME;
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int sscanf(char *, char *, char *, int *, char *, ...);
int /*<<< orphan*/ strptime(char *, char *, struct tm *);
int get_date(struct timeval *tv, char *date) {
  char ctmp[10];
  int itmp;
  struct tm tms;
  if (sscanf(date, "%9s %d %9s %9s %d", ctmp, &itmp, ctmp, ctmp, &itmp) == 5) {
    if (!setlocale(LC_TIME, "en_US"))
      return 1;
    if (!strptime(date, "%B %d %r %Y", &tms))
      return 1;
  } else {
    if (sscanf(date, "%9s %d %9s %d", ctmp, &itmp, ctmp, &itmp) != 4)
      return 1;
    if (!setlocale(LC_TIME, "de_DE"))
      return 1;
    if (!strptime(date, "%B %d %T %Y", &tms))
      return 1;
  }
  tv->tv_sec = mktime(&tms);
  if (tv->tv_sec < 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<get_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rdx
lea    -0x22(%rbp),%r8
lea    -0x22(%rbp),%r9
lea    0xe99(%rip),%rsi
lea    -0x28(%rbp),%rax
mov    %rax,%rcx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x5,%eax
jne    11da <get_date+0x9a>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%eax
jne    11ac <get_date+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
mov    -0x18(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strptime@plt>
cmp    $0x0,%eax
jne    11d5 <get_date+0x95>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
jmp    1268 <get_date+0x128>
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rdx
lea    -0x22(%rbp),%r8
lea    0xe37(%rip),%rsi
lea    -0x28(%rbp),%r9
mov    %r9,%rcx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x4,%eax
je     1210 <get_date+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%eax
jne    123a <get_date+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
mov    -0x18(%rbp),%rdi
lea    0xdf3(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strptime@plt>
cmp    $0x0,%eax
jne    1263 <get_date+0x123>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
jmp    1268 <get_date+0x128>
lea    -0x30(%rbp),%rdi
call   1040 <mktime@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1292 <get_date+0x152>
movl   $0x1,-0x4(%rbp)
jmp    1299 <get_date+0x159>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_date>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0xea2(%rip),%rsi
lea    0x16(%rsp),%rdx
mov    %rbx,%rdi
mov    %rdx,%r8
mov    %rdx,%r9
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x5,%eax
jne    119f <get_date+0x5f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <setlocale@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     120d <get_date+0xcd>
lea    0xe7b(%rip),%rsi
jmp    11ea <get_date+0xaa>
lea    0xe7e(%rip),%rsi
lea    0x16(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %rdx,%r8
mov    %rcx,%r9
xor    %eax,%eax
call   1030 <sscanf@plt>
mov    $0x1,%ebp
cmp    $0x4,%eax
jne    120d <get_date+0xcd>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1050 <setlocale@plt>
test   %eax,%eax
je     120d <get_date+0xcd>
lea    0xe4e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <strptime@plt>
test   %eax,%eax
je     120d <get_date+0xcd>
lea    0x8(%rsp),%rdi
call   1040 <mktime@plt>
mov    %eax,%ebp
mov    %eax,(%r14)
shr    $0x1f,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%9s %d %9s %9s %d\00"
@LC_TIME = global i32 0
@.str.1 = [6 x i8] c"en_US\00"
@.str.2 = [12 x i8] c"%B %d %r %Y\00"
@.str.3 = [14 x i8] c"%9s %d %9s %d\00"
@.str.4 = [6 x i8] c"de_DE\00"
@.str.5 = [12 x i8] c"%B %d %T %Y\00"
define i32 @get_date(%struct.timeval* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.timeval*
%5 = alloca i8*
%6 = alloca [10 x i8]
%7 = alloca i32
%8 = alloca %struct.tm
store %struct.timeval* %0, %struct.timeval** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, i8*, i8*, i32*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10, i32* %7, i8* %11, i8* %12, i32* %7)
%14 = icmp eq i32 %13, 5
br i1 %14, label %15, label %26
15: ; preds = %2
%16 = load i32, i32* @LC_TIME
%17 = call i32 @setlocale(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 1, i32* %3
br label %54
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i32 @strptime(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %8)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20
store i32 1, i32* %3
br label %54
25: ; preds = %20
br label %44
26: ; preds = %2
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%30 = call i32 (i8*, i8*, i8*, i32*, i8*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32* %7, i8* %29, i32* %7)
%31 = icmp ne i32 %30, 4
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %3
br label %54
33: ; preds = %26
%34 = load i32, i32* @LC_TIME
%35 = call i32 @setlocale(i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i32 1, i32* %3
br label %54
38: ; preds = %33
%39 = load i8*, i8** %5
%40 = call i32 @strptime(i8* %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %8)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
store i32 1, i32* %3
br label %54
43: ; preds = %38
br label %44
44: ; preds = %43, %25
%45 = call i32 @mktime(%struct.tm* %8)
%46 = load %struct.timeval*, %struct.timeval** %4
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %46, i32 0, i32 0
store i32 %45, i32* %47
%48 = load %struct.timeval*, %struct.timeval** %4
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 1, i32* %3
br label %54
53: ; preds = %44
store i32 0, i32* %3
br label %54
54: ; preds = %53, %52, %42, %37, %32, %24, %19
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%9s %d %9s %9s %d\00"
@LC_TIME = global i32 0
@.str.1 = [6 x i8] c"en_US\00"
@.str.2 = [12 x i8] c"%B %d %r %Y\00"
@.str.3 = [14 x i8] c"%9s %d %9s %d\00"
@.str.4 = [6 x i8] c"de_DE\00"
@.str.5 = [12 x i8] c"%B %d %T %Y\00"
define i32 @get_date(%struct.timeval* nocapture writeonly %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca %struct.tm
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.tm* %5 to i8*
%9 = call i32 (i8*, i8*, i8*, i32*, i8*, ...) @sscanf(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %4, i8* %6, i8* %6, i32* %4)
%10 = icmp eq i32 %9, 5
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @LC_TIME
%13 = call i32 @setlocale(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %11
%16 = call i32 @strptime(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %32, label %28
18: ; preds = %2
%19 = call i32 (i8*, i8*, i8*, i32*, i8*, ...) @sscanf(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32* %4, i8* %6, i32* %4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i32, i32* @LC_TIME
%23 = call i32 @setlocale(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = call i32 @strptime(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25, %15
%29 = call i32 @mktime(%struct.tm* %5)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %29, i32* %30
%31 = lshr i32 %29, 31
br label %32
32: ; preds = %28, %25, %21, %18, %15, %11
%33 = phi i32 [ 1, %11 ], [ 1, %15 ], [ 1, %18 ], [ 1, %21 ], [ 1, %25 ], [ %31, %28 ]
ret i32 %33
}