#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 tm_sec;
  int tm_min;
  int tm_hour;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_wday;
  int tm_yday;
  int tm_isdst;
};

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int, int,
                           int, int);
char *tm_as_json(const struct tm *date) {
  char *date_json = malloc(sizeof(char) * 512);
  sprintf(date_json,
          "\"tm_sec\": %d, \"tm_min\": %d, \"tm_hour\": %d, \"tm_mday\": %d, "
          "\"tm_mon\": %d, \"tm_year\": %d, \"tm_wday\": %d, \"tm_yday\": %d, "
          "\"tm_isdst\": %d",
          date->tm_sec, date->tm_min, date->tm_hour, date->tm_mday,
          date->tm_mon, date->tm_year, date->tm_wday, date->tm_yday,
          date->tm_isdst);
  return date_json;
}


x86 assembly (clang, -O0):
<tm_as_json>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,-0x18(%rbp)
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r14d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%ebx
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r11d
mov    -0x18(%rbp),%rax
mov    0x1c(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%eax
lea    0xe75(%rip),%rsi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_as_json>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
mov    0xc(%rbx),%r9d
mov    0x10(%rbx),%r10d
mov    0x14(%rbx),%r11d
mov    0x18(%rbx),%r15d
mov    0x1c(%rbx),%eax
mov    0x20(%rbx),%ebx
sub    $0x8,%rsp
lea    0xea1(%rip),%rsi
mov    %r14,%rdi
push   %rbx
push   %rax
push   %r15
push   %r11
push   %r10
call   1040 <sprintf@plt>
add    $0x30,%rsp
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@.str = [132 x i8] c"\22tm_sec\22: %d, \22tm_min\22: %d, \22tm_hour\22: %d, \22tm_mday\22: %d, \22tm_mon\22: %d, \22tm_year\22: %d, \22tm_wday\22: %d, \22tm_yday\22: %d, \22tm_isdst\22: %d\00"
define i8* @tm_as_json(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i8*
store %struct.tm* %0, %struct.tm** %2
%4 = call i8* @malloc(i32 512)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.tm*, %struct.tm** %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load %struct.tm*, %struct.tm** %2
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 2
%14 = load i32, i32* %13
%15 = load %struct.tm*, %struct.tm** %2
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 3
%17 = load i32, i32* %16
%18 = load %struct.tm*, %struct.tm** %2
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 4
%20 = load i32, i32* %19
%21 = load %struct.tm*, %struct.tm** %2
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 5
%23 = load i32, i32* %22
%24 = load %struct.tm*, %struct.tm** %2
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 6
%26 = load i32, i32* %25
%27 = load %struct.tm*, %struct.tm** %2
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 7
%29 = load i32, i32* %28
%30 = load %struct.tm*, %struct.tm** %2
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 8
%32 = load i32, i32* %31
%33 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %14, i32 %17, i32 %20, i32 %23, i32 %26, i32 %29, i32 %32)
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@.str = [132 x i8] c"\22tm_sec\22: %d, \22tm_min\22: %d, \22tm_hour\22: %d, \22tm_mday\22: %d, \22tm_mon\22: %d, \22tm_year\22: %d, \22tm_wday\22: %d, \22tm_yday\22: %d, \22tm_isdst\22: %d\00"
define noalias i8* @tm_as_json(%struct.tm* nocapture %0) {
%2 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%3 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 7
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 8
%20 = load i32, i32* %19
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %6, i32 %8, i32 %10, i32 %12, i32 %14, i32 %16, i32 %18, i32 %20)
ret i8* %2
}