#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*/ assert(int);
char *bufinsert(char, char *);
char *getbufend();
char *getbufstart();
char *bufinsertstr(char *start, char *end, char *t) {
  char *i;
  unsigned d;
  assert((t >= getbufstart() && t <= getbufend()));
  assert(end >= start);
  for (i = start; i < end; i++, t++)
    if (!(t = bufinsert(*i, t)))
      return t;
  d = end - start;
  return t - d;
}


x86 assembly (clang, -O0):
<bufinsertstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <getbufstart@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x2d(%rbp)
jb     1197 <bufinsertstr+0x57>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <getbufend@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
setbe  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    121e <bufinsertstr+0xde>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <bufinsert@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fc <bufinsertstr+0xbc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1241 <bufinsertstr+0x101>
jmp    1201 <bufinsertstr+0xc1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c1 <bufinsertstr+0x81>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufinsertstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getbufstart@plt>
cmp    %rbx,%rax
ja     116e <bufinsertstr+0x2e>
xor    %eax,%eax
call   1030 <getbufend@plt>
xor    %ebp,%ebp
cmp    %rbx,%rax
setae  %bpl
mov    %ebp,%edi
call   1050 <assert@plt>
xor    %edi,%edi
cmp    %r15,%r14
setae  %dil
call   1050 <assert@plt>
sub    %r15,%r14
jbe    11b2 <bufinsertstr+0x72>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbp,1),%edi
mov    %rbx,%rsi
call   1060 <bufinsert@plt>
test   %rax,%rax
je     11ba <bufinsertstr+0x7a>
mov    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1190 <bufinsertstr+0x50>
mov    %r14d,%eax
sub    %rax,%rbx
jmp    11bc <bufinsertstr+0x7c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bufinsertstr(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i8* (...) @getbufstart()
%12 = icmp uge i8* %10, %11
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i8* (...) @getbufend()
%16 = icmp ule i8* %14, %15
br label %17
17: ; preds = %13, %3
%18 = phi i1 [ false, %3 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = icmp uge i8* %21, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i8*, i8** %5
store i8* %26, i8** %8
br label %27
27: ; preds = %40, %17
%28 = load i8*, i8** %8
%29 = load i8*, i8** %6
%30 = icmp ult i8* %28, %29
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = load i8*, i8** %7
%35 = call i8* @bufinsert(i8 signext %33, i8* %34)
store i8* %35, i8** %7
%36 = icmp ne i8* %35, null
br i1 %36, label %39, label %37
37: ; preds = %31
%38 = load i8*, i8** %7
store i8* %38, i8** %4
br label %57
39: ; preds = %31
br label %40
40: ; preds = %39
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %8
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
br label %27
45: ; preds = %27
%46 = load i8*, i8** %6
%47 = load i8*, i8** %5
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
store i32 %51, i32* %9
%52 = load i8*, i8** %7
%53 = load i32, i32* %9
%54 = zext i32 %53 to i64
%55 = sub i64 0, %54
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8* %56, i8** %4
br label %57
57: ; preds = %45, %37
%58 = load i8*, i8** %4
ret i8* %58
}

LLVM IR (-O2):
define i8* @bufinsertstr(i8* %0, i8* %1, i8* %2) {
%4 = ptrtoint i8* %0 to i64
%5 = ptrtoint i8* %1 to i64
%6 = tail call i8* (...) @getbufstart()
%7 = icmp ugt i8* %6, %2
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = tail call i8* (...) @getbufend()
%10 = icmp uge i8* %9, %2
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %8, %3
%13 = phi i32 [ 0, %3 ], [ %11, %8 ]
%14 = tail call i32 @assert(i32 %13)
%15 = icmp uge i8* %1, %0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ult i8* %0, %1
%19 = sub i64 %5, %4
br i1 %18, label %20, label %32
20: ; preds = %12
%21 = getelementptr i8, i8* %0, i64 %19
br label %22
22: ; preds = %20, %28
%23 = phi i8* [ %29, %28 ], [ %0, %20 ]
%24 = phi i8* [ %30, %28 ], [ %2, %20 ]
%25 = load i8, i8* %23
%26 = tail call i8* @bufinsert(i8 signext %25, i8* %24)
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %28
28: ; preds = %22
%29 = getelementptr inbounds i8, i8* %23, i64 1
%30 = getelementptr inbounds i8, i8* %26, i64 1
%31 = icmp eq i8* %29, %21
br i1 %31, label %32, label %22
32: ; preds = %28, %12
%33 = phi i8* [ %2, %12 ], [ %30, %28 ]
%34 = and i64 %19, 4294967295
%35 = sub nsw i64 0, %34
%36 = getelementptr inbounds i8, i8* %33, i64 %35
br label %37
37: ; preds = %22, %32
%38 = phi i8* [ %36, %32 ], [ null, %22 ]
ret i8* %38
}