#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 list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, char *, char const *);
void *list_get(struct list const *, unsigned int);
unsigned int list_size(struct list const *);
char *strdup(char *);
char *str_concat_list(const struct list *list,
                      const char *(*get_str__)(void *)) {
  if (!list) {
    return strdup("");
  }
  unsigned s = list_size(list);
  char *code = "";
  for (unsigned i = 1; i <= s; ++i) {
    asprintf(&code, "%s%s", code, get_str__(list_get(list, i)));
  }
  return code;
}


x86 assembly (clang, -O0):
<str_concat_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <str_concat_list+0x30>
lea    0xea2(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ec <str_concat_list+0xac>
mov    -0x10(%rbp),%rdi
call   1040 <list_size@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     11e4 <str_concat_list+0xa4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <list_get@plt>
mov    %rax,%rdi
mov    -0x40(%rbp),%rax
call   *%rax
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    -0x28(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118e <str_concat_list+0x4e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_concat_list>:
test   %rdi,%rdi
je     11c3 <str_concat_list+0x83>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <list_size@plt>
lea    0xea2(%rip),%rbx
mov    %rbx,(%rsp)
test   %eax,%eax
je     11b1 <str_concat_list+0x71>
mov    %eax,%r12d
mov    $0x1,%ebp
lea    0xe8b(%rip),%rbx
mov    %rsp,%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <list_get@plt>
mov    %rax,%rdi
call   *%r14
mov    %r13,%rdi
lea    0xe66(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <asprintf@plt>
add    $0x1,%ebp
mov    (%rsp),%rbx
cmp    %r12d,%ebp
jbe    1180 <str_concat_list+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3a(%rip),%rdi
jmp    1060 <strdup@plt>

LLVM IR (-O0):
%struct.list = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @str_concat_list(%struct.list* %0, i8* (i8*)* %1) {
%3 = alloca i8*
%4 = alloca %struct.list*
%5 = alloca i8* (i8*)*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.list* %0, %struct.list** %4
store i8* (i8*)* %1, i8* (i8*)** %5
%9 = load %struct.list*, %struct.list** %4
%10 = icmp ne %struct.list* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %3
br label %33
13: ; preds = %2
%14 = load %struct.list*, %struct.list** %4
%15 = call i32 @list_size(%struct.list* %14)
store i32 %15, i32* %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 1, i32* %8
br label %16
16: ; preds = %28, %13
%17 = load i32, i32* %8
%18 = load i32, i32* %6
%19 = icmp ule i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i8* (i8*)*, i8* (i8*)** %5
%23 = load %struct.list*, %struct.list** %4
%24 = load i32, i32* %8
%25 = call i8* @list_get(%struct.list* %23, i32 %24)
%26 = call i8* %22(i8* %25)
%27 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %8
%30 = add i32 %29, 1
store i32 %30, i32* %8
br label %16
31: ; preds = %16
%32 = load i8*, i8** %7
store i8* %32, i8** %3
br label %33
33: ; preds = %31, %11
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
%struct.list = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @str_concat_list(%struct.list* %0, i8* (i8*)* nocapture %1) {
%3 = alloca i8*
%4 = icmp eq %struct.list* %0, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %22
7: ; preds = %2
%8 = tail call i32 @list_size(%struct.list* %0)
%9 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %13, %7
%12 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ], [ %21, %13 ]
br label %22
13: ; preds = %7, %13
%14 = phi i8* [ %21, %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ]
%15 = phi i32 [ %19, %13 ], [ 1, %7 ]
%16 = call i8* @list_get(%struct.list* %0, i32 %15)
%17 = call i8* %1(i8* %16)
%18 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %17)
%19 = add i32 %15, 1
%20 = icmp ugt i32 %19, %8
%21 = load i8*, i8** %3
br i1 %20, label %11, label %13
22: ; preds = %11, %5
%23 = phi i8* [ %12, %11 ], [ %6, %5 ]
ret i8* %23
}