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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gmtime(int *);
scalar_t__ malloc(int);
char *strchr(char *, char);
scalar_t__ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int *);
char *gmtdate(time_t secs) {
  char *s, *nl;
  if (secs == -2) {
    time(&secs);
  }
  if (secs < 0) {
    return NULL;
  }
  s = (char *)malloc(sizeof(char) * 64);
  if (s == NULL) {
    return NULL;
  }
  if (strftime(s, 64, "%a, %d %b %Y %T GMT", gmtime(&secs)) == 0) {
    free(s);
    return NULL;
  }
  nl = strchr(s, '\n');
  if (nl != NULL) {
    *nl = '\0';
  }
  return s;
}


x86 assembly (clang, -O0):
<gmtdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0xfffffffe,-0xc(%rbp)
jne    117e <gmtdate+0x1e>
lea    -0xc(%rbp),%rdi
call   1050 <time@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1195 <gmtdate+0x35>
movq   $0x0,-0x8(%rbp)
jmp    122f <gmtdate+0xcf>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <gmtdate+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    122f <gmtdate+0xcf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <gmtime@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%ecx
mov    $0x40,%esi
lea    0xe22(%rip),%rdx
call   1070 <strftime@plt>
cmp    $0x0,%rax
jne    1203 <gmtdate+0xa3>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    122f <gmtdate+0xcf>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1227 <gmtdate+0xc7>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gmtdate>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
cmp    $0xfffffffe,%edi
jne    117c <gmtdate+0x1c>
lea    0xc(%rsp),%rdi
call   1050 <time@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
js     11d6 <gmtdate+0x76>
mov    $0x40,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d6 <gmtdate+0x76>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
call   1080 <gmtime@plt>
lea    0xe5d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1070 <strftime@plt>
test   %rax,%rax
je     11ce <gmtdate+0x6e>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d8 <gmtdate+0x78>
movb   $0x0,(%rax)
jmp    11d8 <gmtdate+0x78>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
define i8* @gmtdate(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -2
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @time(i32* %3)
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* null, i8** %2
br label %37
14: ; preds = %10
%15 = call i64 @malloc(i32 64)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
store i8* null, i8** %2
br label %37
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i32 @gmtime(i32* %3)
%23 = call i64 @strftime(i8* %21, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
store i8* null, i8** %2
br label %37
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = call i8* @strchr(i8* %29, i8 signext 10)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i8*, i8** %5
store i8 0, i8* %34
br label %35
35: ; preds = %33, %28
%36 = load i8*, i8** %4
store i8* %36, i8** %2
br label %37
37: ; preds = %35, %25, %19, %13
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
define i8* @gmtdate(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = icmp eq i32 %0, -2
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = call i32 @time(i32* %2)
%6 = load i32, i32* %2
br label %7
7: ; preds = %4, %1
%8 = phi i32 [ %6, %4 ], [ %0, %1 ]
%9 = icmp slt i32 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %7
%11 = call i64 @malloc(i32 64)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = call i32 @gmtime(i32* %2)
%16 = call i64 @strftime(i8* %12, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @free(i8* %12)
br label %24
20: ; preds = %14
%21 = call i8* @strchr(i8* %12, i8 signext 10)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20
store i8 0, i8* %21
br label %24
24: ; preds = %20, %23, %10, %7, %18
%25 = phi i8* [ null, %18 ], [ null, %7 ], [ null, %10 ], [ %12, %23 ], [ %12, %20 ]
ret i8* %25
}