#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 (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)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    115f <strptime_httpdate+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <strptime_httpdate+0xc5>
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x2c,%eax
jne    1193 <strptime_httpdate+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    11f5 <strptime_httpdate+0xc5>
movsbl -0x19(%rbp),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%rax
je     11c3 <strptime_httpdate+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    11f5 <strptime_httpdate+0xc5>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jne    11ed <strptime_httpdate+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1050 <strptime@plt>
mov    %rax,-0x8(%rbp)
jmp    11f5 <strptime_httpdate+0xc5>
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
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    114b <strptime_httpdate+0x1b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x3(%rbx),%bpl
cmp    $0x2c,%bpl
jne    115e <strptime_httpdate+0x2e>
lea    0xea4(%rip),%rsi
jmp    1182 <strptime_httpdate+0x52>
movsbl %bpl,%edi
call   1040 <isalpha@plt>
test   %rax,%rax
je     1175 <strptime_httpdate+0x45>
lea    0xea1(%rip),%rsi
jmp    1182 <strptime_httpdate+0x52>
cmp    $0x20,%bpl
jne    1144 <strptime_httpdate+0x14>
lea    0xea6(%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 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %39
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 3
%14 = load i8, i8* %13
store i8 %14, i8* %6
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 44
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = load %struct.tm*, %struct.tm** %5
%21 = call i8* @strptime(i8* %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %20)
store i8* %21, i8** %3
br label %39
22: ; preds = %11
%23 = load i8, i8* %6
%24 = call i64 @isalpha(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load %struct.tm*, %struct.tm** %5
%29 = call i8* @strptime(i8* %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %28)
store i8* %29, i8** %3
br label %39
30: ; preds = %22
%31 = load i8, i8* %6
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = load %struct.tm*, %struct.tm** %5
%37 = call i8* @strptime(i8* %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %36)
store i8* %37, i8** %3
br label %39
38: ; preds = %30
store i8* null, i8** %3
br label %39
39: ; preds = %38, %34, %26, %18, %10
%40 = load i8*, i8** %3
ret i8* %40
}

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 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 4
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 44
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i64 @isalpha(i8 signext %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = icmp eq i8 %7, 32
br i1 %13, label %14, label %17
14: ; preds = %12, %9, %5
%15 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %12 ]
%16 = tail call i8* @strptime(i8* %0, i8* %15, %struct.tm* %1)
br label %17
17: ; preds = %14, %12, %2
%18 = phi i8* [ null, %2 ], [ null, %12 ], [ %16, %14 ]
ret i8* %18
}