#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_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int, int,
                           char *, ...);
char *strerror(int);
char *create_log_message(struct tm *time_info, int log_level, char *message,
                         int errno_number) {
  char *log_ptr;
  if ((log_ptr = (char *)malloc(1024 * sizeof(char))) == NULL) {
    perror("malloc() error");
    exit(EXIT_FAILURE);
  }
  if (errno_number < 0) {
    sprintf(log_ptr, "[LOG #%d %d/%d/%d %d:%d:%d] %s\n", log_level,
            time_info->tm_mday + 1, time_info->tm_mon + 1,
            time_info->tm_year + 1900, time_info->tm_hour, time_info->tm_min,
            time_info->tm_sec, message);
  } else {
    sprintf(log_ptr, "[LOG #%d %d/%d/%d %d:%d:%d] %s : %s\n", log_level,
            time_info->tm_mday + 1, time_info->tm_mon + 1,
            time_info->tm_year + 1900, time_info->tm_hour, time_info->tm_min,
            time_info->tm_sec, message, strerror(errno_number));
  }
  return log_ptr;
}


x86 assembly (clang, -O0):
<create_log_message>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    $0x400,%edi
call   1030 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    119e <create_log_message+0x4e>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    1213 <create_log_message+0xc3>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9d
add    $0x76c,%r9d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%ebx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r11d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%r10d
mov    -0x28(%rbp),%rax
lea    0xe1a(%rip),%rsi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12b1 <create_log_message+0x161>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r14d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%ebx
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    -0x50(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x48(%rbp),%r9d
mov    -0x44(%rbp),%r11d
mov    -0x40(%rbp),%r10
lea    0xd9c(%rip),%rsi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_log_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %rdx,0x8(%rsp)
mov    %esi,0x4(%rsp)
mov    %rdi,%r15
mov    $0x400,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1230 <create_log_message+0xe0>
mov    %rax,%r12
mov    (%r15),%ebx
mov    0x4(%r15),%r13d
add    $0x1,%ebx
add    $0x1,%r13d
mov    $0x76c,%ebp
add    0x8(%r15),%ebp
mov    0xc(%r15),%r10d
mov    0x10(%r15),%r11d
mov    0x14(%r15),%r15d
test   %r14d,%r14d
js     11f3 <create_log_message+0xa3>
mov    %r14d,%edi
mov    %r10,0x10(%rsp)
mov    %r11,%r14
call   1070 <strerror@plt>
mov    %rax,%r10
sub    $0x8,%rsp
lea    0xe66(%rip),%rsi
mov    %r12,%rdi
mov    0xc(%rsp),%edx
mov    %ebx,%ecx
mov    %r13d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
push   %r10
push   0x18(%rsp)
push   %r15
push   %r14
push   0x38(%rsp)
call   1050 <sprintf@plt>
add    $0x30,%rsp
jmp    121e <create_log_message+0xce>
lea    0xe15(%rip),%rsi
mov    %r12,%rdi
mov    0x4(%rsp),%edx
mov    %ebx,%ecx
mov    %r13d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
push   0x8(%rsp)
push   %r15
push   %r11
push   %r10
call   1050 <sprintf@plt>
add    $0x20,%rsp
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc9(%rip),%rdi
call   1040 <perror@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"malloc() error\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"[LOG #%d %d/%d/%d %d:%d:%d] %s\0A\00"
@.str.2 = [37 x i8] c"[LOG #%d %d/%d/%d %d:%d:%d] %s : %s\0A\00"
define i8* @create_log_message(%struct.tm* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.tm*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store %struct.tm* %0, %struct.tm** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %9
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %4
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %17
%21 = load i8*, i8** %9
%22 = load i32, i32* %6
%23 = load %struct.tm*, %struct.tm** %5
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
%27 = load %struct.tm*, %struct.tm** %5
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
%31 = load %struct.tm*, %struct.tm** %5
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1900
%35 = load %struct.tm*, %struct.tm** %5
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = load %struct.tm*, %struct.tm** %5
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 4
%40 = load i32, i32* %39
%41 = load %struct.tm*, %struct.tm** %5
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 5
%43 = load i32, i32* %42
%44 = load i8*, i8** %7
%45 = call i32 (i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %26, i32 %30, i32 %34, i32 %37, i32 %40, i32 %43, i8* %44)
br label %74
46: ; preds = %17
%47 = load i8*, i8** %9
%48 = load i32, i32* %6
%49 = load %struct.tm*, %struct.tm** %5
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
%53 = load %struct.tm*, %struct.tm** %5
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
%57 = load %struct.tm*, %struct.tm** %5
%58 = getelementptr inbounds %struct.tm, %struct.tm* %57, i32 0, i32 2
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1900
%61 = load %struct.tm*, %struct.tm** %5
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 3
%63 = load i32, i32* %62
%64 = load %struct.tm*, %struct.tm** %5
%65 = getelementptr inbounds %struct.tm, %struct.tm* %64, i32 0, i32 4
%66 = load i32, i32* %65
%67 = load %struct.tm*, %struct.tm** %5
%68 = getelementptr inbounds %struct.tm, %struct.tm* %67, i32 0, i32 5
%69 = load i32, i32* %68
%70 = load i8*, i8** %7
%71 = load i32, i32* %8
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %52, i32 %56, i32 %60, i32 %63, i32 %66, i32 %69, i8* %70, i8* %72)
br label %74
74: ; preds = %46, %20
%75 = load i8*, i8** %9
ret i8* %75
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"malloc() error\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"[LOG #%d %d/%d/%d %d:%d:%d] %s\0A\00"
@.str.2 = [37 x i8] c"[LOG #%d %d/%d/%d %d:%d:%d] %s : %s\0A\00"
define i8* @create_log_message(%struct.tm* nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i64 @malloc(i32 1024)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4
%13 = icmp slt i32 %3, 0
%14 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%28 = load i32, i32* %27
br i1 %13, label %29, label %31
29: ; preds = %12
%30 = tail call i32 (i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %16, i32 %19, i32 %22, i32 %24, i32 %26, i32 %28, i8* %2)
br label %34
31: ; preds = %12
%32 = tail call i8* @strerror(i32 %3)
%33 = tail call i32 (i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %16, i32 %19, i32 %22, i32 %24, i32 %26, i32 %28, i8* %2, i8* %32)
br label %34
34: ; preds = %31, %29
ret i8* %6
}