#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*/ errx(int, char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
scalar_t__ strlen(char *);
char *appdstr(char *s, const char *tp, size_t len) {
  char *mp;
  const char *sp;
  int ch;
  char *m;
  if ((m = malloc(strlen(s) + len + 1)) == NULL)
    errx(1, "malloc");
  for (mp = m, sp = s; (*mp++ = *sp++) != '\0';)
    ;
  --mp;
  if (*(mp - 1) == '\\')
    --mp;
  while ((ch = *mp++ = *tp++) && ch != '\n')
    ;
  *mp = '\0';
  free(s);
  return (m);
}


x86 assembly (clang, -O0):
<appdstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    118c <appdstr+0x4c>
mov    $0x1,%edi
lea    0xe79(%rip),%rsi
call   1050 <errx@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11cf <appdstr+0x8f>
jmp    119c <appdstr+0x5c>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5c,%eax
jne    11f8 <appdstr+0xb8>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11fd <appdstr+0xbd>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %al,(%rcx)
movsbl %al,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     123d <appdstr+0xfd>
cmpl   $0xa,-0x2c(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    124d <appdstr+0x10d>
jmp    1252 <appdstr+0x112>
jmp    11fd <appdstr+0xbd>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appdstr>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1179 <appdstr+0x39>
lea    0xe91(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    %r15,%rax
add    $0xffffffffffffffff,%rax
mov    %r14,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rcx),%edx
add    $0x1,%rcx
mov    %dl,0x1(%rax)
add    $0x1,%rax
test   %dl,%dl
jne    1190 <appdstr+0x50>
cmpb   $0x5c,-0x1(%rax)
lea    -0x1(%rax),%rcx
cmovne %rax,%rcx
xor    %eax,%eax
movzbl (%rbx,%rax,1),%edx
mov    %dl,(%rcx,%rax,1)
add    $0x1,%rax
cmp    $0xa,%dl
je     11c4 <appdstr+0x84>
test   %dl,%dl
jne    11b0 <appdstr+0x70>
movb   $0x0,(%rcx,%rax,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
define noalias i8* @appdstr(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %2, 1
%6 = add i64 %5, %4
%7 = tail call i8* @malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
br label %12
12: ; preds = %11, %12
%13 = phi i8* [ %15, %12 ], [ %0, %11 ]
%14 = phi i8* [ %17, %12 ], [ %7, %11 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %16, i8* %14
%18 = icmp eq i8 %16, 0
br i1 %18, label %19, label %12
19: ; preds = %12
%20 = getelementptr inbounds i8, i8* %14, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 92
%23 = select i1 %22, i8* %20, i8* %14
br label %24
24: ; preds = %24, %19
%25 = phi i8* [ %23, %19 ], [ %29, %24 ]
%26 = phi i8* [ %1, %19 ], [ %27, %24 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %26
%29 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %28, i8* %25
switch i8 %28, label %24 [
i8 10, label %30
i8 0, label %30
]
30: ; preds = %24, %24
store i8 0, i8* %29
%31 = tail call i32 @free(i8* %0)
ret i8* %7
}