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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ *strptime(char const *, char *, struct tm *);
char *strstr(char const *, char *);
scalar_t__ timegm(struct tm *);
time_t qtime_parse_gmtstr(const char *gmtstr) {
  struct tm gmtm;
  if (strptime(gmtstr, "%a, %d %b %Y %H:%M:%S", &gmtm) == NULL)
    return 0;
  time_t utc = timegm(&gmtm);
  if (utc < 0)
    return -1;
  char *p;
  if ((p = strstr(gmtstr, "+")) != NULL) {
    utc -= ((atoi(p + 1) / 100) * 60 * 60);
    if (utc < 0)
      return -1;
  } else if ((p = strstr(gmtstr, "-")) != NULL) {
    utc += ((atoi(p + 1) / 100) * 60 * 60);
  }
  return utc;
}


x86 assembly (clang, -O0):
<qtime_parse_gmtstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <strptime@plt>
cmp    $0x0,%rax
jne    1177 <qtime_parse_gmtstr+0x37>
movq   $0x0,-0x8(%rbp)
jmp    1250 <qtime_parse_gmtstr+0x110>
lea    -0x18(%rbp),%rdi
call   1030 <timegm@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    119c <qtime_parse_gmtstr+0x5c>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1250 <qtime_parse_gmtstr+0x110>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1200 <qtime_parse_gmtstr+0xc0>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11fb <qtime_parse_gmtstr+0xbb>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1250 <qtime_parse_gmtstr+0x110>
jmp    1248 <qtime_parse_gmtstr+0x108>
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1243 <qtime_parse_gmtstr+0x103>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1248 <qtime_parse_gmtstr+0x108>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtime_parse_gmtstr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xead(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <strptime@plt>
test   %rax,%rax
je     11c2 <qtime_parse_gmtstr+0x82>
lea    0x8(%rsp),%rdi
call   1040 <timegm@plt>
mov    $0xffffffffffffffff,%r15
test   %rax,%rax
js     1209 <qtime_parse_gmtstr+0xc9>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c7 <qtime_parse_gmtstr+0x87>
add    $0x1,%rax
mov    %rax,%rdi
call   1050 <atoi@plt>
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0xe10,%eax,%eax
cltq
sub    %rax,%r14
jns    1206 <qtime_parse_gmtstr+0xc6>
jmp    1209 <qtime_parse_gmtstr+0xc9>
xor    %r15d,%r15d
jmp    1209 <qtime_parse_gmtstr+0xc9>
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1206 <qtime_parse_gmtstr+0xc6>
add    $0x1,%rax
mov    %rax,%rdi
call   1050 <atoi@plt>
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0xe10,%eax,%eax
cltq
add    %rax,%r14
mov    %r14,%r15
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [22 x i8] c"%a, %d %b %Y %H:%M:%S\00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c"-\00"
define i64 @qtime_parse_gmtstr(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.tm
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @strptime(i8* %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i64 0, i64* %2
br label %51
11: ; preds = %1
%12 = call i64 @timegm(%struct.tm* %4)
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i64 -1, i64* %2
br label %51
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @atoi(i8* %22)
%24 = sdiv i32 %23, 100
%25 = mul nsw i32 %24, 60
%26 = mul nsw i32 %25, 60
%27 = sext i32 %26 to i64
%28 = load i64, i64* %5
%29 = sub nsw i64 %28, %27
store i64 %29, i64* %5
%30 = load i64, i64* %5
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %20
store i64 -1, i64* %2
br label %51
33: ; preds = %20
br label %49
34: ; preds = %16
%35 = load i8*, i8** %3
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %36, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = call i32 @atoi(i8* %40)
%42 = sdiv i32 %41, 100
%43 = mul nsw i32 %42, 60
%44 = mul nsw i32 %43, 60
%45 = sext i32 %44 to i64
%46 = load i64, i64* %5
%47 = add nsw i64 %46, %45
store i64 %47, i64* %5
br label %48
48: ; preds = %38, %34
br label %49
49: ; preds = %48, %33
%50 = load i64, i64* %5
store i64 %50, i64* %2
br label %51
51: ; preds = %49, %32, %15, %10
%52 = load i64, i64* %2
ret i64 %52
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [22 x i8] c"%a, %d %b %Y %H:%M:%S\00"
define i64 @qtime_parse_gmtstr(i8* %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = call i32* @strptime(i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %32, label %6
6: ; preds = %1
%7 = call i64 @timegm(%struct.tm* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %6
%10 = call i8* @strchr(i8* dereferenceable(1) %0, i32 43)
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = call i32 @atoi(i8* %13)
%15 = sdiv i32 %14, 100
%16 = mul i32 %15, 3600
%17 = sext i32 %16 to i64
%18 = sub nsw i64 %7, %17
%19 = icmp slt i64 %18, 0
br i1 %19, label %32, label %30
20: ; preds = %9
%21 = call i8* @strchr(i8* dereferenceable(1) %0, i32 45)
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %21, i64 1
%25 = call i32 @atoi(i8* %24)
%26 = sdiv i32 %25, 100
%27 = mul i32 %26, 3600
%28 = sext i32 %27 to i64
%29 = add nsw i64 %7, %28
br label %30
30: ; preds = %20, %23, %12
%31 = phi i64 [ %18, %12 ], [ %29, %23 ], [ %7, %20 ]
br label %32
32: ; preds = %6, %12, %30, %1
%33 = phi i64 [ 0, %1 ], [ -1, %6 ], [ %31, %30 ], [ -1, %12 ]
ret i64 %33
}