#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *get_token(char *start, char *end) {
  char *token;
  if (start >= end) {
    return NULL;
  }
  if ((token = malloc((end - start + 1) * sizeof(char))) == NULL) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  snprintf(token, (end - start + 1) * sizeof(char), "%s", start);
  token[end - start] = '\0';
  return token;
}


x86 assembly (clang, -O0):
<get_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     116b <get_token+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <get_token+0xb1>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ad <get_token+0x6d>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe36(%rip),%rdx
call   1030 <snprintf@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):
<get_token>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %rsi,%rdi
jae    1182 <get_token+0x42>
mov    %rsi,%rbx
mov    %rdi,%r14
sub    %rdi,%rbx
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1193 <get_token+0x53>
mov    %rax,%r15
lea    0xe99(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
call   1030 <snprintf@plt>
movb   $0x0,(%r15,%rbx,1)
jmp    1185 <get_token+0x45>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i8* @get_token(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** %4
%8 = load i8*, i8** %5
%9 = icmp uge i8* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %46
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = add nsw i64 %16, 1
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%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 = add nsw i64 %32, 1
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = load i8*, i8** %4
%37 = call i32 @snprintf(i8* %27, i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %6
%39 = load i8*, i8** %5
%40 = load i8*, i8** %4
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = getelementptr inbounds i8, i8* %38, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %6
store i8* %45, i8** %3
br label %46
46: ; preds = %26, %10
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i8* @get_token(i8* %0, i8* %1) {
%3 = icmp ult i8* %0, %1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %4
%17 = tail call i32 @snprintf(i8* %10, i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%18 = getelementptr inbounds i8, i8* %10, i64 %7
store i8 0, i8* %18
br label %19
19: ; preds = %2, %16
%20 = phi i8* [ %10, %16 ], [ null, %2 ]
ret i8* %20
}