#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 */
typedef int ssize_t;

/* Variables and functions */
char **strbuf_copy(char **, int);
int strbuf_len(char **);
char **strbuf_slice(char **buf, size_t i, ssize_t j) {
  if (j == -1)
    j = strbuf_len(buf);
  else if (j < i)
    return NULL;
  return strbuf_copy(buf + i, j - i);
}


x86 assembly (clang, -O0):
<strbuf_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    114e <strbuf_slice+0x2e>
mov    -0x10(%rbp),%rdi
call   1030 <strbuf_len@plt>
mov    %eax,-0x1c(%rbp)
jmp    116e <strbuf_slice+0x4e>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1169 <strbuf_slice+0x49>
movq   $0x0,-0x8(%rbp)
jmp    1190 <strbuf_slice+0x70>
jmp    116e <strbuf_slice+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %eax,%esi
call   1040 <strbuf_copy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strbuf_slice>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0xffffffff,%edx
je     1141 <strbuf_slice+0x21>
movslq %edx,%rax
cmp    %rbx,%rax
jae    114b <strbuf_slice+0x2b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <strbuf_len@plt>
mov    %eax,%edx
lea    (%r14,%rbx,8),%rdi
sub    %ebx,%edx
mov    %edx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strbuf_copy@plt>

LLVM IR (-O0):
define i8** @strbuf_slice(i8** %0, i64 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8**, i8*** %5
%12 = call i32 @strbuf_len(i8** %11)
store i32 %12, i32* %7
br label %20
13: ; preds = %3
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = load i64, i64* %6
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i8** null, i8*** %4
br label %30
19: ; preds = %13
br label %20
20: ; preds = %19, %10
%21 = load i8**, i8*** %5
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = load i64, i64* %6
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i8** @strbuf_copy(i8** %23, i32 %28)
store i8** %29, i8*** %4
br label %30
30: ; preds = %20, %18
%31 = load i8**, i8*** %4
ret i8** %31
}

LLVM IR (-O2):
define i8** @strbuf_slice(i8** %0, i64 %1, i32 %2) {
%4 = icmp eq i32 %2, -1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @strbuf_len(i8** %0)
br label %10
7: ; preds = %3
%8 = sext i32 %2 to i64
%9 = icmp ult i64 %8, %1
br i1 %9, label %16, label %10
10: ; preds = %7, %5
%11 = phi i32 [ %6, %5 ], [ %2, %7 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %1
%13 = trunc i64 %1 to i32
%14 = sub i32 %11, %13
%15 = tail call i8** @strbuf_copy(i8** %12, i32 %14)
br label %16
16: ; preds = %7, %10
%17 = phi i8** [ %15, %10 ], [ null, %7 ]
ret i8** %17
}