#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 /*<<< orphan*/ time_t;
struct tm {
  size_t tm_wday;
  int tm_mday;
  size_t tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ *gmtime_r(int /*<<< orphan*/ *, struct tm *);
int snprintf(char *, int, char *, char const *, int, char const *, int, int,
             int, int);
int timet_to_httpdate(time_t t, char *str, int strlen) {
  static const char *day_of_week[] = {"Sun", "Mon", "Tue", "Wed",
                                      "Thu", "Fri", "Sat"};
  static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  struct tm gm;
  if (gmtime_r(&t, &gm) == NULL)
    return (-1);
  if (snprintf(str, strlen, "%s, %02d %s %4d %02d:%02d:%02d GMT",
               day_of_week[gm.tm_wday], gm.tm_mday, months[gm.tm_mon],
               gm.tm_year + 1900, gm.tm_hour, gm.tm_min, gm.tm_sec) == strlen)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<timet_to_httpdate>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1040 <gmtime_r@plt>
cmp    $0x0,%rax
jne    1156 <timet_to_httpdate+0x36>
movl   $0xffffffff,-0xc(%rbp)
jmp    11cc <timet_to_httpdate+0xac>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x48(%rbp),%rcx
lea    0x2ed8(%rip),%rax
mov    (%rax,%rcx,8),%rcx
mov    -0x40(%rbp),%r8d
mov    -0x38(%rbp),%rdx
lea    0x2f05(%rip),%rax
mov    (%rax,%rdx,8),%r9
mov    -0x30(%rbp),%ebx
add    $0x76c,%ebx
mov    -0x2c(%rbp),%r11d
mov    -0x28(%rbp),%r10d
mov    -0x24(%rbp),%eax
lea    0xeb2(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1030 <snprintf@plt>
cmp    -0x1c(%rbp),%eax
jne    11c5 <timet_to_httpdate+0xa5>
movl   $0xffffffff,-0xc(%rbp)
jmp    11cc <timet_to_httpdate+0xac>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<timet_to_httpdate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <gmtime_r@plt>
test   %rax,%rax
je     11b2 <timet_to_httpdate+0x92>
mov    0x10(%rsp),%rax
lea    0xeac(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
mov    0x18(%rsp),%r8d
mov    0x20(%rsp),%rax
lea    0xeb0(%rip),%rdx
movslq (%rdx,%rax,4),%r9
mov    $0x76c,%eax
add    0x28(%rsp),%eax
add    %rdx,%r9
mov    0x2c(%rsp),%r10d
mov    0x30(%rsp),%ebx
mov    0x34(%rsp),%ebp
lea    0xf08(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
push   %rbp
push   %rbx
push   %r10
push   %rax
call   1030 <snprintf@plt>
add    $0x20,%rsp
mov    %eax,%ecx
xor    %eax,%eax
cmp    %r14d,%ecx
sete   %al
neg    %eax
jmp    11b7 <timet_to_httpdate+0x97>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i32, i64, i32, i32, i32, i32 }
@timet_to_httpdate.day_of_week = internal global [7 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0)]
@.str = [4 x i8] c"Sun\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@.str.6 = [4 x i8] c"Sat\00"
@timet_to_httpdate.months = internal global [12 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.18, i32 0, i32 0)]
@.str.7 = [4 x i8] c"Jan\00"
@.str.8 = [4 x i8] c"Feb\00"
@.str.9 = [4 x i8] c"Mar\00"
@.str.10 = [4 x i8] c"Apr\00"
@.str.11 = [4 x i8] c"May\00"
@.str.12 = [4 x i8] c"Jun\00"
@.str.13 = [4 x i8] c"Jul\00"
@.str.14 = [4 x i8] c"Aug\00"
@.str.15 = [4 x i8] c"Sep\00"
@.str.16 = [4 x i8] c"Oct\00"
@.str.17 = [4 x i8] c"Nov\00"
@.str.18 = [4 x i8] c"Dec\00"
@.str.19 = [35 x i8] c"%s, %02d %s %4d %02d:%02d:%02d GMT\00"
define i32 @timet_to_httpdate(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.tm
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = call i32* @gmtime_r(i32* %5, %struct.tm* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %39
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* @timet_to_httpdate.day_of_week, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 2
%22 = load i64, i64* %21
%23 = getelementptr inbounds [12 x i8*], [12 x i8*]* @timet_to_httpdate.months, i64 0, i64 %22
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 3
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1900
%28 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 5
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 6
%33 = load i32, i32* %32
%34 = call i32 @snprintf(i8* %13, i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i8* %18, i32 %20, i8* %24, i32 %27, i32 %29, i32 %31, i32 %33)
%35 = load i32, i32* %7
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %12
store i32 -1, i32* %4
br label %39
38: ; preds = %12
store i32 0, i32* %4
br label %39
39: ; preds = %38, %37, %11
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.tm = type { i64, i32, i64, i32, i32, i32, i32 }
@reltable.timet_to_httpdate = internal unnamed_addr constant [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.timet_to_httpdate to i64)) to i32)]
@.str = [4 x i8] c"Sun\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@.str.6 = [4 x i8] c"Sat\00"
@reltable.timet_to_httpdate.20 = internal unnamed_addr constant [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.7 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.8 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.9 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.10 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.11 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.12 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.13 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.14 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.15 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.16 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.17 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.18 to i64), i64 ptrtoint ([12 x i32]* @reltable.timet_to_httpdate.20 to i64)) to i32)]
@.str.7 = [4 x i8] c"Jan\00"
@.str.8 = [4 x i8] c"Feb\00"
@.str.9 = [4 x i8] c"Mar\00"
@.str.10 = [4 x i8] c"Apr\00"
@.str.11 = [4 x i8] c"May\00"
@.str.12 = [4 x i8] c"Jun\00"
@.str.13 = [4 x i8] c"Jul\00"
@.str.14 = [4 x i8] c"Aug\00"
@.str.15 = [4 x i8] c"Sep\00"
@.str.16 = [4 x i8] c"Oct\00"
@.str.17 = [4 x i8] c"Nov\00"
@.str.18 = [4 x i8] c"Dec\00"
@.str.19 = [35 x i8] c"%s, %02d %s %4d %02d:%02d:%02d GMT\00"
define i32 @timet_to_httpdate(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %0, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = call i32* @gmtime_r(i32* %4, %struct.tm* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %32, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%11 = load i64, i64* %10
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.timet_to_httpdate to i8*), i64 %12)
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%17 = load i64, i64* %16
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.timet_to_httpdate.20 to i8*), i64 %18)
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 6
%28 = load i32, i32* %27
%29 = call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i8* %13, i32 %15, i8* %19, i32 %22, i32 %24, i32 %26, i32 %28)
%30 = icmp eq i32 %29, %2
%31 = sext i1 %30 to i32
br label %32
32: ; preds = %9, %3
%33 = phi i32 [ -1, %3 ], [ %31, %9 ]
ret i32 %33
}