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

/* Variables and functions */
scalar_t__ isalpha(char);
int strlen(char const *);
char *strptime(char const *, char *, struct tm *);
char *strptime_httpdate(const char *s, struct tm *tm) {
  if (!s || strlen(s) < 4)
    return NULL;
  char defining_char = *(s + 3);
  if (defining_char == ',') {
    return strptime(s, "%a, %d %b %Y %T GMT", tm);
  } else if (isalpha(defining_char)) {
    return strptime(s, "%A, %d-%b-%y %T GMT", tm);
  } else if (defining_char == ' ') {
    return strptime(s, "%a %b %d %T %Y", tm);
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<strptime_httpdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115d <strptime_httpdate+0x2d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    116a <strptime_httpdate+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1200 <strptime_httpdate+0xd0>
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x2c,%eax
jne    119e <strptime_httpdate+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <strptime_httpdate+0xd0>
movsbl -0x19(%rbp),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%rax
je     11ce <strptime_httpdate+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <strptime_httpdate+0xd0>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jne    11f8 <strptime_httpdate+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <strptime_httpdate+0xd0>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strptime_httpdate>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1149 <strptime_httpdate+0x19>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    1150 <strptime_httpdate+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x3(%rbx),%bpl
cmp    $0x2c,%bpl
jne    1163 <strptime_httpdate+0x33>
lea    0xe9f(%rip),%rsi
jmp    1187 <strptime_httpdate+0x57>
movsbl %bpl,%edi
call   1040 <isalpha@plt>
test   %rax,%rax
je     117a <strptime_httpdate+0x4a>
lea    0xe9c(%rip),%rsi
jmp    1187 <strptime_httpdate+0x57>
cmp    $0x20,%bpl
jne    1149 <strptime_httpdate+0x19>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <strptime@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
@.str.1 = [20 x i8] c"%A, %d-%b-%y %T GMT\00"
@.str.2 = [15 x i8] c"%a %b %d %T %Y\00"
define i8* @strptime_httpdate(i8* %0, %struct.tm* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i8
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %9, %2
store i8* null, i8** %3
br label %42
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 3
%17 = load i8, i8* %16
store i8 %17, i8* %6
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 44
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = load %struct.tm*, %struct.tm** %5
%24 = call i8* @strptime(i8* %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %23)
store i8* %24, i8** %3
br label %42
25: ; preds = %14
%26 = load i8, i8* %6
%27 = call i64 @isalpha(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load %struct.tm*, %struct.tm** %5
%32 = call i8* @strptime(i8* %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %31)
store i8* %32, i8** %3
br label %42
33: ; preds = %25
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 32
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8*, i8** %4
%39 = load %struct.tm*, %struct.tm** %5
%40 = call i8* @strptime(i8* %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %39)
store i8* %40, i8** %3
br label %42
41: ; preds = %33
store i8* null, i8** %3
br label %42
42: ; preds = %41, %37, %29, %21, %13
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
@.str.1 = [20 x i8] c"%A, %d-%b-%y %T GMT\00"
@.str.2 = [15 x i8] c"%a %b %d %T %Y\00"
define i8* @strptime_httpdate(i8* %0, %struct.tm* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp slt i32 %5, 4
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 3
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 44
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i64 @isalpha(i8 signext %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = icmp eq i8 %9, 32
br i1 %15, label %16, label %19
16: ; preds = %14, %11, %7
%17 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %14 ]
%18 = tail call i8* @strptime(i8* %0, i8* %17, %struct.tm* %1)
br label %19
19: ; preds = %16, %14, %2, %4
%20 = phi i8* [ null, %4 ], [ null, %2 ], [ null, %14 ], [ %18, %16 ]
ret i8* %20
}