#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 *ts_dynarr_pop(char *);
char *ts_dynarr_push(char *, char *);
char *append_dynstr(char *dest, char *s) {
  while (*s) {
    do {
      char cnull = 0, ch = (char)(*s++);
      (dest) = ts_dynarr_pop(dest);
      (dest) = ts_dynarr_push((dest), &ch);
      (dest) = ts_dynarr_push((dest), &cnull);
    } while (0);
  }
  return dest;
}


x86 assembly (clang, -O0):
<append_dynstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     118e <append_dynstr+0x6e>
jmp    1142 <append_dynstr+0x22>
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x12(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ts_dynarr_pop@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1030 <ts_dynarr_push@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x11(%rbp),%rsi
call   1030 <ts_dynarr_push@plt>
mov    %rax,-0x8(%rbp)
jmp    1130 <append_dynstr+0x10>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_dynstr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
mov    (%rsi),%cl
test   %cl,%cl
je     1182 <append_dynstr+0x62>
mov    %rsi,%rbx
add    $0x1,%rbx
lea    0xe(%rsp),%r14
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,0xf(%rsp)
mov    %cl,0xe(%rsp)
mov    %rax,%rdi
call   1040 <ts_dynarr_pop@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <ts_dynarr_push@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <ts_dynarr_push@plt>
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1150 <append_dynstr+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @append_dynstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %7
7: ; preds = %22, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %7
br label %12
12: ; preds = %11
store i8 0, i8* %5
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8, i8* %13
store i8 %15, i8* %6
%16 = load i8*, i8** %3
%17 = call i8* @ts_dynarr_pop(i8* %16)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i8* @ts_dynarr_push(i8* %18, i8* %6)
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = call i8* @ts_dynarr_push(i8* %20, i8* %5)
store i8* %21, i8** %3
br label %22
22: ; preds = %12
br label %7
23: ; preds = %7
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
define i8* @append_dynstr(i8* %0, i8* nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %2, %7
%8 = phi i8 [ %15, %7 ], [ %5, %2 ]
%9 = phi i8* [ %11, %7 ], [ %1, %2 ]
%10 = phi i8* [ %14, %7 ], [ %0, %2 ]
store i8 0, i8* %3
%11 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %8, i8* %4
%12 = call i8* @ts_dynarr_pop(i8* %10)
%13 = call i8* @ts_dynarr_push(i8* %12, i8* %4)
%14 = call i8* @ts_dynarr_push(i8* %13, i8* %3)
%15 = load i8, i8* %11
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %2
%18 = phi i8* [ %0, %2 ], [ %14, %7 ]
ret i8* %18
}