#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*/ ENOMEM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *lstGlue(char **lst) {
  if (lst == NULL) {
    return NULL;
  }
  char *rval = NULL;
  size_t i = 0;
  while (lst[i]) {
    size_t rlen = rval ? strlen(rval) : 0;
    char *t = realloc(rval, rlen + strlen(lst[i]) + 1);
    if (t == NULL) {
      free(rval);
      errno = ENOMEM;
      return NULL;
    }
    rval = t;
    strcpy(rval + rlen, lst[i]);
    i++;
  }
  return rval;
}


x86 assembly (clang, -O0):
<lstGlue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <lstGlue+0x24>
movq   $0x0,-0x8(%rbp)
jmp    125d <lstGlue+0x11d>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1255 <lstGlue+0x115>
cmpq   $0x0,-0x18(%rbp)
je     11a4 <lstGlue+0x64>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    11af <lstGlue+0x6f>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    11af <lstGlue+0x6f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1223 <lstGlue+0xe3>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc4(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    125d <lstGlue+0x11d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1174 <lstGlue+0x34>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lstGlue>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11ec <lstGlue+0xac>
mov    %rdi,%r15
mov    (%rdi),%r14
test   %r14,%r14
je     11ec <lstGlue+0xac>
add    $0x8,%r15
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
test   %r12,%r12
je     1190 <lstGlue+0x50>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
jmp    1193 <lstGlue+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %r13d,%r13d
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rax,%r13,1),%rsi
add    $0x1,%rsi
mov    %r12,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     11d2 <lstGlue+0x92>
mov    %rax,%rbx
add    %rax,%r13
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    (%r15),%r14
add    $0x8,%r15
mov    %rbx,%r12
test   %r14,%r14
jne    1170 <lstGlue+0x30>
jmp    11ee <lstGlue+0xae>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    0x2dee(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @lstGlue(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8** %0, i8*** %3
%8 = load i8**, i8*** %3
%9 = icmp eq i8** %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %57
11: ; preds = %1
store i8* null, i8** %4
store i64 0, i64* %5
br label %12
12: ; preds = %43, %11
%13 = load i8**, i8*** %3
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8*, i8** %13, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %55
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = call i64 @strlen(i8* %22)
br label %25
24: ; preds = %18
br label %25
25: ; preds = %24, %21
%26 = phi i64 [ %23, %21 ], [ 0, %24 ]
store i64 %26, i64* %6
%27 = load i8*, i8** %4
%28 = load i64, i64* %6
%29 = load i8**, i8*** %3
%30 = load i64, i64* %5
%31 = getelementptr inbounds i8*, i8** %29, i64 %30
%32 = load i8*, i8** %31
%33 = call i64 @strlen(i8* %32)
%34 = add i64 %28, %33
%35 = add i64 %34, 1
%36 = call i8* @realloc(i8* %27, i64 %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %25
%40 = load i8*, i8** %4
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* @ENOMEM
store i32 %42, i32* @errno
store i8* null, i8** %2
br label %57
43: ; preds = %25
%44 = load i8*, i8** %7
store i8* %44, i8** %4
%45 = load i8*, i8** %4
%46 = load i64, i64* %6
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = load i8**, i8*** %3
%49 = load i64, i64* %5
%50 = getelementptr inbounds i8*, i8** %48, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @strcpy(i8* %47, i8* %51)
%53 = load i64, i64* %5
%54 = add i64 %53, 1
store i64 %54, i64* %5
br label %12
55: ; preds = %12
%56 = load i8*, i8** %4
store i8* %56, i8** %2
br label %57
57: ; preds = %55, %39, %10
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @lstGlue(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %30, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %30, label %6
6: ; preds = %3, %23
%7 = phi i8* [ %28, %23 ], [ %4, %3 ]
%8 = phi i8* [ %18, %23 ], [ null, %3 ]
%9 = phi i64 [ %26, %23 ], [ 0, %3 ]
%10 = icmp eq i8* %8, null
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i64 @strlen(i8* %8)
br label %13
13: ; preds = %6, %11
%14 = phi i64 [ %12, %11 ], [ 0, %6 ]
%15 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%16 = add i64 %14, 1
%17 = add i64 %16, %15
%18 = tail call i8* @realloc(i8* %8, i64 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = tail call i32 @free(i8* %8)
%22 = load i32, i32* @ENOMEM
store i32 %22, i32* @errno
br label %30
23: ; preds = %13
%24 = getelementptr inbounds i8, i8* %18, i64 %14
%25 = tail call i32 @strcpy(i8* %24, i8* %7)
%26 = add i64 %9, 1
%27 = getelementptr inbounds i8*, i8** %0, i64 %26
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %6
30: ; preds = %23, %3, %20, %1
%31 = phi i8* [ null, %1 ], [ null, %20 ], [ null, %3 ], [ %18, %23 ]
ret i8* %31
}