#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 */
size_t abs(int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *xmalloc(size_t);
int git_release_string_utility_substr(char **out, const char *source, int len) {
  size_t source_len = strlen(source);
  if (source_len < abs(len)) {
    return 1;
  }
  size_t out_len = source_len - abs(len);
  *out = xmalloc(out_len + sizeof(char));
  if (len > 0) {
    memcpy(*out, source + len, out_len);
  } else if (len <= 0) {
    memcpy(*out, source, out_len);
  }
  (*out)[out_len] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<git_release_string_utility_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jae    118c <git_release_string_utility_substr+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    1224 <git_release_string_utility_substr+0xe4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jle    11eb <git_release_string_utility_substr+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%rdx
call   1060 <memcpy@plt>
jmp    120e <git_release_string_utility_substr+0xce>
cmpl   $0x0,-0x1c(%rbp)
jg     1209 <git_release_string_utility_substr+0xc9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <memcpy@plt>
jmp    120e <git_release_string_utility_substr+0xce>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<git_release_string_utility_substr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rcx,%rbx
jb     11a4 <git_release_string_utility_substr+0x64>
mov    %ebp,%edi
call   1030 <abs@plt>
sub    %rax,%rbx
lea    0x1(%rbx),%rdi
call   1050 <xmalloc@plt>
mov    %rax,(%r14)
test   %ebp,%ebp
jle    118d <git_release_string_utility_substr+0x4d>
mov    %ebp,%ecx
add    %rcx,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @git_release_string_utility_substr(i8** %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = load i32, i32* %7
%14 = call i64 @abs(i32 %13)
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 1, i32* %4
br label %52
17: ; preds = %3
%18 = load i64, i64* %8
%19 = load i32, i32* %7
%20 = call i64 @abs(i32 %19)
%21 = sub i64 %18, %20
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = add i64 %22, 1
%24 = call i8* @xmalloc(i64 %23)
%25 = load i8**, i8*** %5
store i8* %24, i8** %25
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i64, i64* %9
%36 = call i32 @memcpy(i8* %30, i8* %34, i64 %35)
br label %47
37: ; preds = %17
%38 = load i32, i32* %7
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = load i8*, i8** %6
%44 = load i64, i64* %9
%45 = call i32 @memcpy(i8* %42, i8* %43, i64 %44)
br label %46
46: ; preds = %40, %37
br label %47
47: ; preds = %46, %28
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
%50 = load i64, i64* %9
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 0, i8* %51
store i32 0, i32* %4
br label %52
52: ; preds = %47, %16
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
define i32 @git_release_string_utility_substr(i8** nocapture %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @abs(i32 %2)
%6 = icmp ult i64 %4, %5
br i1 %6, label %22, label %7
7: ; preds = %3
%8 = tail call i64 @abs(i32 %2)
%9 = sub i64 %4, %8
%10 = add i64 %9, 1
%11 = tail call i8* @xmalloc(i64 %10)
store i8* %11, i8** %0
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = zext i32 %2 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = tail call i32 @memcpy(i8* %11, i8* %15, i64 %9)
br label %19
17: ; preds = %7
%18 = tail call i32 @memcpy(i8* %11, i8* %1, i64 %9)
br label %19
19: ; preds = %17, %13
%20 = load i8*, i8** %0
%21 = getelementptr inbounds i8, i8* %20, i64 %9
store i8 0, i8* %21
br label %22
22: ; preds = %3, %19
%23 = phi i32 [ 0, %19 ], [ 1, %3 ]
ret i32 %23
}