#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(int);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *add_listitem(char *list, char *item) {
  int size = strlen(item) + 6;
  if (list == NULL) {
    list = malloc(size);
    list[0] = 0;
  } else {
    list = realloc(list, strlen(list) + size);
  }
  strcat(list, "<li>");
  strcat(list, item);
  strcat(list, "\n");
  free(item);
  return list;
}


x86 assembly (clang, -O0):
<add_listitem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x6,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1192 <add_listitem+0x42>
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b5 <add_listitem+0x65>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
add    -0x14(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_listitem>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x6,%ebp
test   %rbx,%rbx
je     1185 <add_listitem+0x35>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
jmp    1192 <add_listitem+0x42>
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"<li>\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @add_listitem(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 6
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* %5
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 0, i8* %15
br label %23
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
%22 = call i8* @realloc(i8* %17, i32 %21)
store i8* %22, i8** %3
br label %23
23: ; preds = %16, %11
%24 = load i8*, i8** %3
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %3
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"<li>\00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @add_listitem(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 6
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i8* @malloc(i32 %4)
store i8 0, i8* %7
br label %12
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, %4
%11 = tail call i8* @realloc(i8* %0, i32 %10)
br label %12
12: ; preds = %8, %6
%13 = phi i8* [ %7, %6 ], [ %11, %8 ]
%14 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @strcat(i8* %13, i8* %1)
%16 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @free(i8* %1)
ret i8* %13
}