#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
extern char *str_dupspan(const char *start, const char *limit) {
  char *copy;
  if (!(copy = malloc(limit - start + 1))) {
    return 0;
  }
  memcpy(copy, start, limit - start);
  copy[limit - start] = 0;
  return copy;
}


x86 assembly (clang, -O0):
<str_dupspan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1161 <str_dupspan+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1196 <str_dupspan+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_dupspan>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
sub    %rdi,%r15
lea    0x1(%r15),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1152 <str_dupspan+0x32>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @str_dupspan(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = load i8*, i8** %4
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = add nsw i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i8* null, i8** %3
br label %35
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @memcpy(i8* %18, i8* %19, i32 %25)
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = getelementptr inbounds i8, i8* %27, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
store i8* %34, i8** %3
br label %35
35: ; preds = %17, %16
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @str_dupspan(i8* %0, i8* %1) {
%3 = ptrtoint i8* %1 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @memcpy(i8* %8, i8* %0, i32 %6)
%12 = getelementptr inbounds i8, i8* %8, i64 %5
store i8 0, i8* %12
br label %13
13: ; preds = %2, %10
ret i8* %8
}