#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
char *sub(char *, char *, int, int);
int main() {
  char s[] = "abbbc";
  char *ss;
  printf("Before:\n\ts = [%s]\n", s);
  ss = sub(s, "lladin ", 1, 3);
  printf("After:\n\ts = [%s]\n", ss);
  free(ss);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0xa(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
lea    -0xa(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x1,%edx
mov    $0x3,%ecx
call   1050 <sub@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movw   $0x63,0xc(%rsp)
movl   $0x62626261,0x8(%rsp)
62
lea    0xebb(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    $0x3,%ecx
call   1050 <sub@plt>
mov    %rax,%rbx
lea    0xea6(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.s = [6 x i8] c"abbbc\00"
@.str = [19 x i8] c"Before:\0A\09s = [%s]\0A\00"
@.str.1 = [8 x i8] c"lladin \00"
@.str.2 = [18 x i8] c"After:\0A\09s = [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = bitcast [6 x i8]* %2 to i8*
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%8 = call i8* @sub(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 3)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %3
%12 = call i32 @free(i8* %11)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [6 x i8] c"abbbc\00"
@.str = [19 x i8] c"Before:\0A\09s = [%s]\0A\00"
@.str.1 = [8 x i8] c"lladin \00"
@.str.2 = [18 x i8] c"After:\0A\09s = [%s]\0A\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i8* @sub(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 3)
%5 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = call i32 @free(i8* %4)
ret i32 0
}