#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 error(int, int /*<<< orphan*/);
scalar_t__ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
struct tm *localtime(int /*<<< orphan*/ *);
char *realloc(char *, size_t);
int /*<<< orphan*/ stdout;
size_t strftime(char *, size_t, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int showtime(const char *format) {
  char *buffer;
  size_t buffsize;
  struct tm *nowtm;
  time_t now;
  size_t result;
  now = time(NULL);
  nowtm = localtime(&now);
  buffsize = 30;
  buffer = NULL;
  do {
    buffer = realloc(buffer, buffsize * sizeof(char));
    if (buffer == NULL) {
      return error(15, 0);
    }
    result = strftime(buffer, buffsize, format, nowtm);
    buffsize += 30;
  } while (result == 0 && buffer[0] != 0 && buffsize <= 1000);
  if (result == 0 && buffer[0] != 0) {
    return error(5, 0);
  }
  if (fprintf(stdout, "%s\n", buffer) > 0) {
    free(buffer);
    return 0;
  } else {
    free(buffer);
    return error(3, 0);
  }
}


x86 assembly (clang, -O0):
<showtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1e,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
shl    $0x0,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d9 <showtime+0x69>
mov    $0xf,%edi
xor    %esi,%esi
call   1090 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    12bb <showtime+0x14b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1080 <strftime@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1e,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x39(%rbp)
jne    1231 <showtime+0xc1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     1231 <showtime+0xc1>
cmpq   $0x3e8,-0x20(%rbp)
setbe  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11a5 <showtime+0x35>
cmpq   $0x0,-0x38(%rbp)
jne    126b <showtime+0xfb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     126b <showtime+0xfb>
mov    $0x5,%edi
xor    %esi,%esi
call   1090 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    12bb <showtime+0x14b>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd81(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jle    12a3 <showtime+0x133>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bb <showtime+0x14b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x3,%edi
xor    %esi,%esi
call   1090 <error@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showtime>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r12d,%r12d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
mov    %rax,%r15
mov    $0x1e,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <realloc@plt>
test   %rax,%rax
je     1219 <showtime+0xa9>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1080 <strftime@plt>
test   %rax,%rax
jne    11e8 <showtime+0x78>
movzbl (%r12),%eax
cmp    $0x3ca,%rbx
ja     11df <showtime+0x6f>
add    $0x1e,%rbx
test   %al,%al
jne    11a0 <showtime+0x30>
mov    $0x5,%edi
test   %al,%al
jne    121e <showtime+0xae>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %rbx,%rbx
jg     1225 <showtime+0xb5>
mov    $0x3,%edi
jmp    121e <showtime+0xae>
mov    $0xf,%edi
xor    %esi,%esi
call   1090 <error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @showtime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.tm*
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
%9 = call i32 @time(i32* null)
store i32 %9, i32* %7
%10 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %10, %struct.tm** %6
store i64 30, i64* %5
store i8* null, i8** %4
br label %11
11: ; preds = %40, %1
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = mul i64 %13, 1
%15 = call i8* @realloc(i8* %12, i64 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @error(i32 15, i32 0)
store i32 %19, i32* %2
br label %65
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = load i8*, i8** %3
%24 = load %struct.tm*, %struct.tm** %6
%25 = call i64 @strftime(i8* %21, i64 %22, i8* %23, %struct.tm* %24)
store i64 %25, i64* %8
%26 = load i64, i64* %5
%27 = add i64 %26, 30
store i64 %27, i64* %5
br label %28
28: ; preds = %20
%29 = load i64, i64* %8
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i64, i64* %5
%39 = icmp ule i64 %38, 1000
br label %40
40: ; preds = %37, %31, %28
%41 = phi i1 [ false, %31 ], [ false, %28 ], [ %39, %37 ]
br i1 %41, label %11, label %42
42: ; preds = %40
%43 = load i64, i64* %8
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @error(i32 5, i32 0)
store i32 %52, i32* %2
br label %65
53: ; preds = %45, %42
%54 = load i32, i32* @stdout
%55 = load i8*, i8** %4
%56 = call i64 @fprintf(i32 %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %55)
%57 = icmp sgt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i8*, i8** %4
%60 = call i32 @free(i8* %59)
store i32 0, i32* %2
br label %65
61: ; preds = %53
%62 = load i8*, i8** %4
%63 = call i32 @free(i8* %62)
%64 = call i32 @error(i32 3, i32 0)
store i32 %64, i32* %2
br label %65
65: ; preds = %61, %58, %51, %18
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @showtime(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = call %struct.tm* @localtime(i32* %2)
br label %6
6: ; preds = %14, %1
%7 = phi i64 [ 30, %1 ], [ %15, %14 ]
%8 = phi i8* [ null, %1 ], [ %9, %14 ]
%9 = call i8* @realloc(i8* %8, i64 %7)
%10 = icmp eq i8* %9, null
br i1 %10, label %27, label %11
11: ; preds = %6
%12 = call i64 @strftime(i8* %9, i64 %7, i8* %0, %struct.tm* %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = add nuw nsw i64 %7, 30
%16 = load i8, i8* %9
%17 = icmp ne i8 %16, 0
%18 = icmp ult i64 %7, 971
%19 = and i1 %18, %17
br i1 %19, label %6, label %20
20: ; preds = %14
%21 = icmp eq i8 %16, 0
br i1 %21, label %22, label %27
22: ; preds = %11, %20
%23 = load i32, i32* @stdout
%24 = call i64 @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%25 = icmp sgt i64 %24, 0
%26 = call i32 @free(i8* %9)
br i1 %25, label %30, label %27
27: ; preds = %6, %22, %20
%28 = phi i32 [ 5, %20 ], [ 3, %22 ], [ 15, %6 ]
%29 = call i32 @error(i32 %28, i32 0)
br label %30
30: ; preds = %27, %22
%31 = phi i32 [ 0, %22 ], [ %29, %27 ]
ret i32 %31
}