#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *write_cventry(char *date, char *title, char *group, char *place,
                    char *note, char *contents) {
  char *format = "<p>%s<br>\n<strong>%s</strong>\n<em>%s</em>";
  char *out = malloc(strlen(date) + strlen(title) + strlen(group) +
                     strlen(place) + strlen(note) + strlen(contents) + 46);
  sprintf(out, format, date, title, group);
  free(date);
  free(title);
  free(group);
  if (strlen(place)) {
    strcat(out, ",\n");
    strcat(out, place);
  }
  free(place);
  if (strlen(note)) {
    strcat(out, ",\n");
    strcat(out, note);
  }
  free(note);
  strcat(out, ".<br>\n");
  strcat(out, contents);
  free(contents);
  return out;
}


x86 assembly (clang, -O0):
<write_cventry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
add    $0x2e,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1265 <write_cventry+0x115>
mov    -0x40(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     129e <write_cventry+0x14e>
mov    -0x40(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_cventry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r12
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rdx,0x10(%rsp)
mov    %rsi,%rbx
mov    %rsi,0x18(%rsp)
mov    %rdi,0x20(%rsp)
call   1040 <strlen@plt>
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r13,0x28(%rsp)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r12,0x30(%rsp)
mov    %r12,%rdi
call   1040 <strlen@plt>
add    0x8(%rsp),%r15
add    %rbp,%r15
add    %rbx,%r15
add    %r13,%r15
lea    (%rax,%r15,1),%rdi
add    $0x2e,%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe17(%rip),%rsi
mov    %rax,%rdi
mov    0x20(%rsp),%rbx
mov    %rbx,%rdx
mov    0x18(%rsp),%rbp
mov    %rbp,%rcx
mov    0x10(%rsp),%r12
mov    %r12,%r8
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
cmpb   $0x0,(%r14)
je     1241 <write_cventry+0xf1>
lea    0xdfc(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rbp
cmpb   $0x0,0x0(%rbp)
je     126e <write_cventry+0x11e>
lea    0xdcf(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xdb0(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    0x30(%rsp),%rbp
mov    %rbp,%rsi
call   1060 <strcat@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"<p>%s<br>\0A<strong>%s</strong>\0A<em>%s</em>\00"
@.str.1 = [3 x i8] c",\0A\00"
@.str.2 = [7 x i8] c".<br>\0A\00"
define i8* @write_cventry(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8** %13
%15 = load i8*, i8** %7
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %8
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = load i8*, i8** %9
%21 = call i64 @strlen(i8* %20)
%22 = add nsw i64 %19, %21
%23 = load i8*, i8** %10
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %22, %24
%26 = load i8*, i8** %11
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %25, %27
%29 = load i8*, i8** %12
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %28, %30
%32 = add nsw i64 %31, 46
%33 = call i8* @malloc(i64 %32)
store i8* %33, i8** %14
%34 = load i8*, i8** %14
%35 = load i8*, i8** %13
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = call i32 @sprintf(i8* %34, i8* %35, i8* %36, i8* %37, i8* %38)
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %9
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %10
%47 = call i64 @strlen(i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %6
%50 = load i8*, i8** %14
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%52 = load i8*, i8** %14
%53 = load i8*, i8** %10
%54 = call i32 @strcat(i8* %52, i8* %53)
br label %55
55: ; preds = %49, %6
%56 = load i8*, i8** %10
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %11
%59 = call i64 @strlen(i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %55
%62 = load i8*, i8** %14
%63 = call i32 @strcat(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%64 = load i8*, i8** %14
%65 = load i8*, i8** %11
%66 = call i32 @strcat(i8* %64, i8* %65)
br label %67
67: ; preds = %61, %55
%68 = load i8*, i8** %11
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %14
%71 = call i32 @strcat(i8* %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%72 = load i8*, i8** %14
%73 = load i8*, i8** %12
%74 = call i32 @strcat(i8* %72, i8* %73)
%75 = load i8*, i8** %12
%76 = call i32 @free(i8* %75)
%77 = load i8*, i8** %14
ret i8* %77
}

LLVM IR (-O2):
@.str = [42 x i8] c"<p>%s<br>\0A<strong>%s</strong>\0A<em>%s</em>\00"
@.str.1 = [3 x i8] c",\0A\00"
@.str.2 = [7 x i8] c".<br>\0A\00"
define i8* @write_cventry(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%13 = add i64 %7, 46
%14 = add i64 %13, %8
%15 = add i64 %14, %9
%16 = add i64 %15, %10
%17 = add i64 %16, %11
%18 = add i64 %17, %12
%19 = tail call i8* @malloc(i64 %18)
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%21 = tail call i32 @free(i8* %0)
%22 = tail call i32 @free(i8* %1)
%23 = tail call i32 @free(i8* %2)
%24 = load i8, i8* %3
%25 = icmp eq i8 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %6
%27 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @strcat(i8* %19, i8* %3)
br label %29
29: ; preds = %26, %6
%30 = tail call i32 @free(i8* %3)
%31 = load i8, i8* %4
%32 = icmp eq i8 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = tail call i32 @strcat(i8* %19, i8* %4)
br label %36
36: ; preds = %33, %29
%37 = tail call i32 @free(i8* %4)
%38 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%39 = tail call i32 @strcat(i8* %19, i8* %5)
%40 = tail call i32 @free(i8* %5)
ret i8* %19
}