#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*/ printf(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void substr(char *str, int s, int l) {
  char ret[l + 1];
  char *str2;
  str2 = str + s;
  strncpy(ret, str2, l);
  ret[l] = '\0';
  printf("Ret: %s \n", ret);
}


x86 assembly (clang, -O0):
<substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rsi
movslq -0x10(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substr>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edx,%r14d
lea    0x1(%r14),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movslq %esi,%rsi
add    %rdi,%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
movslq %r14d,%rax
movb   $0x0,(%rax,%rbx,1)
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Ret: %s \0A\00"
define void @substr(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = load i32, i32* %6
%21 = call i32 @strncpy(i8* %14, i8* %19, i32 %20)
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %14, i64 %23
store i8 0, i8* %24
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %14)
%26 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Ret: %s \0A\00"
define void @substr(i8* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = call i32 @strncpy(i8* %6, i8* %8, i32 %2)
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %11
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
ret void
}