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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *gmtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *cur_time(char *fmt) {
  int len = 200;
  char *outstr;
  time_t t;
  struct tm *tmp;
  outstr = malloc(len);
  t = time(NULL);
  tmp = gmtime(&t);
  if (tmp == NULL) {
    perror("gmtime");
    return NULL;
  }
  if (strftime(outstr, len, fmt, tmp) == 0) {
    fprintf(stderr, "strftime returned 0");
    return NULL;
  }
  return outstr;
}


x86 assembly (clang, -O0):
<cur_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xc8,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1080 <gmtime@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bc <cur_time+0x5c>
lea    0xe56(%rip),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <cur_time+0xa4>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    11fc <cur_time+0x9c>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <cur_time+0xa4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cur_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xc8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1080 <gmtime@plt>
test   %rax,%rax
je     11c8 <cur_time+0x68>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
jne    11bd <cur_time+0x5d>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe31(%rip),%rdi
call   1070 <perror@plt>
jmp    11bb <cur_time+0x5b>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"gmtime\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"strftime returned 0\00"
define i8* @cur_time(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %3
store i32 200, i32* %4
%8 = load i32, i32* %4
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %5
%10 = call i32 @time(i32* null)
store i32 %10, i32* %6
%11 = call %struct.tm* @gmtime(i32* %6)
store %struct.tm* %11, %struct.tm** %7
%12 = load %struct.tm*, %struct.tm** %7
%13 = icmp eq %struct.tm* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %28
16: ; preds = %1
%17 = load i8*, i8** %5
%18 = load i32, i32* %4
%19 = load i8*, i8** %3
%20 = load %struct.tm*, %struct.tm** %7
%21 = call i64 @strftime(i8* %17, i32 %18, i8* %19, %struct.tm* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %28
26: ; preds = %16
%27 = load i8*, i8** %5
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %23, %14
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"gmtime\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"strftime returned 0\00"
define i8* @cur_time(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call dereferenceable_or_null(200) i8* @malloc(i32 200)
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @gmtime(i32* %2)
%7 = icmp eq %struct.tm* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %1
%11 = call i64 @strftime(i8* %4, i32 200, i8* %0, %struct.tm* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %10, %13, %8
%17 = phi i8* [ null, %8 ], [ null, %13 ], [ %4, %10 ]
ret i8* %17
}