#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 */
scalar_t__ 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 = (char *)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 i64 @malloc(i32 512)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = load %struct.tm*, %struct.tm** %2
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.tm*, %struct.tm** %2
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load %struct.tm*, %struct.tm** %2
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = load %struct.tm*, %struct.tm** %2
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 3
%18 = load i32, i32* %17
%19 = load %struct.tm*, %struct.tm** %2
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 4
%21 = load i32, i32* %20
%22 = load %struct.tm*, %struct.tm** %2
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 5
%24 = load i32, i32* %23
%25 = load %struct.tm*, %struct.tm** %2
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 6
%27 = load i32, i32* %26
%28 = load %struct.tm*, %struct.tm** %2
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 7
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %2
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 8
%33 = load i32, i32* %32
%34 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12, i32 %15, i32 %18, i32 %21, i32 %24, i32 %27, i32 %30, i32 %33)
%35 = load i8*, i8** %3
ret i8* %35
}

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 i8* @tm_as_json(%struct.tm* nocapture %0) {
%2 = tail call i64 @malloc(i32 512)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 7
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 8
%21 = load i32, i32* %20
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7, i32 %9, i32 %11, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21)
ret i8* %3
}