#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 */
char *find_next_token(char const **, unsigned int *);
char *variable_buffer_output(char *, char const *, int);
char *func_join(char *o, char **argv,
                const char *funcname __attribute__((unused))) {
  int doneany = 0;
  const char *tp;
  const char *pp;
  const char *list1_iterator = argv[0];
  const char *list2_iterator = argv[1];
  do {
    unsigned int len1, len2;
    tp = find_next_token(&list1_iterator, &len1);
    if (tp != 0)
      o = variable_buffer_output(o, tp, len1);
    pp = find_next_token(&list2_iterator, &len2);
    if (pp != 0)
      o = variable_buffer_output(o, pp, len2);
    if (tp != 0 || pp != 0) {
      o = variable_buffer_output(o, " ", 1);
      doneany = 1;
    }
  } while (tp != 0 || pp != 0);
  if (doneany)
    --o;
  return o;
}


x86 assembly (clang, -O0):
<func_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1040 <find_next_token@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1182 <func_join+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1030 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1040 <find_next_token@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b2 <func_join+0x92>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   1030 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <func_join+0xa8>
cmpq   $0x0,-0x30(%rbp)
je     11e8 <func_join+0xc8>
mov    -0x8(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x1,%edx
call   1030 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    11ed <func_join+0xcd>
mov    $0x1,%al
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x49(%rbp)
jne    1208 <func_join+0xe8>
cmpq   $0x0,-0x30(%rbp)
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1152 <func_join+0x32>
cmpl   $0x0,-0x1c(%rbp)
je     1229 <func_join+0x109>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbp
mov    (%rsi),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x8(%rsp)
xor    %r14d,%r14d
lea    0x4(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %rsp,%rbx
lea    0xea7(%rip),%r13
jmp    119b <func_join+0x7b>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <find_next_token@plt>
test   %rax,%rax
je     11d1 <func_join+0xb1>
mov    (%rsp),%edx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <variable_buffer_output@plt>
mov    %rax,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <variable_buffer_output@plt>
mov    %rax,%rbp
mov    $0xffffffffffffffff,%r14
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1040 <find_next_token@plt>
test   %rax,%rax
je     1160 <func_join+0x40>
mov    0x4(%rsp),%edx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <variable_buffer_output@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <find_next_token@plt>
test   %rax,%rax
jne    1170 <func_join+0x50>
jmp    1181 <func_join+0x61>
add    %r14,%rbp
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @func_join(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
store i8* %16, i8** %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %11
br label %20
20: ; preds = %54, %3
%21 = call i8* @find_next_token(i8** %10, i32* %12)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8*, i8** %8
%27 = load i32, i32* %12
%28 = call i8* @variable_buffer_output(i8* %25, i8* %26, i32 %27)
store i8* %28, i8** %4
br label %29
29: ; preds = %24, %20
%30 = call i8* @find_next_token(i8** %11, i32* %13)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = load i8*, i8** %9
%36 = load i32, i32* %13
%37 = call i8* @variable_buffer_output(i8* %34, i8* %35, i32 %36)
store i8* %37, i8** %4
br label %38
38: ; preds = %33, %29
%39 = load i8*, i8** %8
%40 = icmp ne i8* %39, null
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i8*, i8** %9
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41, %38
%45 = load i8*, i8** %4
%46 = call i8* @variable_buffer_output(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i8* %46, i8** %4
store i32 1, i32* %7
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47
%49 = load i8*, i8** %8
%50 = icmp ne i8* %49, null
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i8*, i8** %9
%53 = icmp ne i8* %52, null
br label %54
54: ; preds = %51, %48
%55 = phi i1 [ true, %48 ], [ %53, %51 ]
br i1 %55, label %20, label %56
56: ; preds = %54
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i32 -1
store i8* %61, i8** %4
br label %62
62: ; preds = %59, %56
%63 = load i8*, i8** %4
ret i8* %63
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @func_join(i8* %0, i8** nocapture %1, i8* nocapture readnone %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i8** %4 to i8*
%9 = load i8*, i8** %1
store i8* %9, i8** %4
%10 = bitcast i8** %5 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %5
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
br label %15
15: ; preds = %33, %3
%16 = phi i64 [ -1, %33 ], [ 0, %3 ]
%17 = phi i8* [ %35, %33 ], [ %0, %3 ]
%18 = call i8* @find_next_token(i8** %4, i32* %6)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i8* @find_next_token(i8** %5, i32* %7)
%22 = icmp eq i8* %21, null
br i1 %22, label %36, label %28
23: ; preds = %15
%24 = load i32, i32* %6
%25 = call i8* @variable_buffer_output(i8* %17, i8* %18, i32 %24)
%26 = call i8* @find_next_token(i8** %5, i32* %7)
%27 = icmp eq i8* %26, null
br i1 %27, label %33, label %28
28: ; preds = %23, %20
%29 = phi i8* [ %26, %23 ], [ %21, %20 ]
%30 = phi i8* [ %25, %23 ], [ %17, %20 ]
%31 = load i32, i32* %7
%32 = call i8* @variable_buffer_output(i8* %30, i8* %29, i32 %31)
br label %33
33: ; preds = %23, %28
%34 = phi i8* [ %32, %28 ], [ %25, %23 ]
%35 = call i8* @variable_buffer_output(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %15
36: ; preds = %20
%37 = getelementptr i8, i8* %17, i64 %16
ret i8* %37
}