#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 */
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *subString(const char *input, int offset, int len, char *dest) {
  int input_len = (int)strlen(input);
  if (offset + len > input_len) {
    return NULL;
  }
  strncpy(dest, input + offset, (size_t)len);
  return dest;
}


x86 assembly (clang, -O0):
<subString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    115e <subString+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    117e <subString+0x5e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
movslq -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    (%r15,%r12,1),%ecx
cmp    %eax,%ecx
jle    1146 <subString+0x26>
xor    %r14d,%r14d
jmp    115a <subString+0x3a>
movslq %r12d,%rax
add    %rax,%rbx
movslq %r15d,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @subString(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = add nsw i32 %2, %1
%8 = icmp sgt i32 %7, %6
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = sext i32 %2 to i64
%13 = tail call i32 @strncpy(i8* %3, i8* %11, i64 %12)
br label %14
14: ; preds = %4, %9
%15 = phi i8* [ %3, %9 ], [ null, %4 ]
ret i8* %15
}