#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 */
struct tm {
  int dummy;
};
struct disc_time {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ format_output(char *, struct disc_time *);
struct disc_time *get_ddate(struct tm *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void print_ddate(const char *format, struct tm *current_tm) {
  static char *form = NULL;
  struct disc_time *dt;
  if ((dt = get_ddate(current_tm)) == NULL)
    return;
  if (form == NULL)
    if ((form = malloc(strlen(format) + 1)) == NULL)
      return;
  strcpy(form, format);
  format_output(form, dt);
}


x86 assembly (clang, -O0):
<print_ddate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_ddate@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117c <print_ddate+0x2c>
jmp    11da <print_ddate+0x8a>
cmpq   $0x0,0x2ecc(%rip)
jne    11ba <print_ddate+0x6a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,0x2eaa(%rip)
cmp    $0x0,%rax
jne    11b5 <print_ddate+0x65>
jmp    11da <print_ddate+0x8a>
jmp    11ba <print_ddate+0x6a>
mov    0x2e8f(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e7f(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <format_output@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ddate>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <get_ddate@plt>
test   %rax,%rax
je     11b1 <print_ddate+0x61>
mov    %rax,%rbx
mov    0x2ee2(%rip),%rdi
test   %rdi,%rdi
jne    1193 <print_ddate+0x43>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rdi
mov    %rax,0x2ec2(%rip)
test   %rax,%rax
je     11b1 <print_ddate+0x61>
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2eae(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <format_output@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.disc_time = type { i32 }
@print_ddate.form = internal global i8* null
define void @print_ddate(i8* %0, %struct.tm* %1) {
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = alloca %struct.disc_time*
store i8* %0, i8** %3
store %struct.tm* %1, %struct.tm** %4
%6 = load %struct.tm*, %struct.tm** %4
%7 = call %struct.disc_time* @get_ddate(%struct.tm* %6)
store %struct.disc_time* %7, %struct.disc_time** %5
%8 = icmp eq %struct.disc_time* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %28
10: ; preds = %2
%11 = load i8*, i8** @print_ddate.form
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** @print_ddate.form
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %13
br label %28
20: ; preds = %13
br label %21
21: ; preds = %20, %10
%22 = load i8*, i8** @print_ddate.form
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** @print_ddate.form
%26 = load %struct.disc_time*, %struct.disc_time** %5
%27 = call i32 @format_output(i8* %25, %struct.disc_time* %26)
br label %28
28: ; preds = %21, %19, %9
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.disc_time = type { i32 }
@print_ddate.form = internal unnamed_addr global i8* null
define void @print_ddate(i8* %0, %struct.tm* %1) {
%3 = tail call %struct.disc_time* @get_ddate(%struct.tm* %1)
%4 = icmp eq %struct.disc_time* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = load i8*, i8** @print_ddate.form
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add nsw i64 %9, 1
%11 = tail call i8* @malloc(i64 %10)
store i8* %11, i8** @print_ddate.form
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %8, %5
%14 = phi i8* [ %11, %8 ], [ %6, %5 ]
%15 = tail call i32 @strcpy(i8* %14, i8* %0)
%16 = load i8*, i8** @print_ddate.form
%17 = tail call i32 @format_output(i8* %16, %struct.disc_time* %3)
br label %18
18: ; preds = %8, %2, %13
ret void
}