int main() {
  char str1[256] = "ihello";
  char str2[256] = "hello";
  char str3[256];
  String_Sub(str3, str1, 0, 2);
  printf("str3: %s\n", str3);
  printf("%s, %s\n", str1, str2);
  printf("strlength: %d\n", String_Length(str1));
  printf("strcat: %s\n", String_Concat(str1, str2));
  printf("strindex: %d\n", String_Index(str1, str2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movb   $0x69,-0x110(%rbp)
movb   $0x68,-0x10f(%rbp)
movb   $0x65,-0x10e(%rbp)
movb   $0x6c,-0x10d(%rbp)
movb   $0x6c,-0x10c(%rbp)
movb   $0x6f,-0x10b(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movb   $0x68,-0x210(%rbp)
movb   $0x65,-0x20f(%rbp)
movb   $0x6c,-0x20e(%rbp)
movb   $0x6c,-0x20d(%rbp)
movb   $0x6f,-0x20c(%rbp)
lea    -0x310(%rbp),%rdi
lea    -0x110(%rbp),%rsi
xor    %edx,%edx
mov    $0x2,%ecx
mov    $0x0,%al
call   1030 <String_Sub@plt>
lea    -0x310(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    -0x210(%rbp),%rdx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    $0x0,%al
call   1070 <String_Length@plt>
mov    %eax,%esi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x0,%al
call   1080 <String_Concat@plt>
mov    %eax,%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x0,%al
call   1060 <String_Index@plt>
mov    %eax,%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x300,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movl   $0x6c656869,0x100(%rsp)
69 68 65 6c
movw   $0x6f6c,0x104(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x6c6c6568,(%rsp)
movb   $0x6f,0x4(%rsp)
lea    0x200(%rsp),%rbx
lea    0x100(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1030 <String_Sub@plt>
lea    0xd6e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd67(%rip),%rdi
mov    %rsp,%r14
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <String_Length@plt>
lea    0xd4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <String_Concat@plt>
lea    0xd40(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <String_Index@plt>
lea    0xd2f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x300,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"str3: %s\0A\00"
@.str.1 = [8 x i8] c"%s, %s\0A\00"
@.str.2 = [15 x i8] c"strlength: %d\0A\00"
@.str.3 = [12 x i8] c"strcat: %s\0A\00"
@.str.4 = [14 x i8] c"strindex: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = bitcast [256 x i8]* %2 to i8*
%6 = bitcast i8* %5 to [256 x i8]*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 0
store i8 105, i8* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 1
store i8 104, i8* %8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 2
store i8 101, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 3
store i8 108, i8* %10
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 4
store i8 108, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i32 0, i32 5
store i8 111, i8* %12
%13 = bitcast [256 x i8]* %3 to i8*
%14 = bitcast i8* %13 to [256 x i8]*
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i32 0, i32 0
store i8 104, i8* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i32 0, i32 1
store i8 101, i8* %16
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i32 0, i32 2
store i8 108, i8* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i32 0, i32 3
store i8 108, i8* %18
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i32 0, i32 4
store i8 111, i8* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @String_Sub to i32 (i8*, i8*, i32, i32, ...)*)(i8* %20, i8* %21, i32 0, i32 2)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%29 = call i32 (i8*, ...) bitcast (i32 (...)* @String_Length to i32 (i8*, ...)*)(i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @String_Concat to i32 (i8*, i8*, ...)*)(i8* %31, i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%37 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @String_Index to i32 (i8*, i8*, ...)*)(i8* %35, i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"str3: %s\0A\00"
@.str.1 = [8 x i8] c"%s, %s\0A\00"
@.str.2 = [15 x i8] c"strlength: %d\0A\00"
@.str.3 = [12 x i8] c"strcat: %s\0A\00"
@.str.4 = [14 x i8] c"strindex: %d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
store i8 105, i8* %4
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 1
store i8 104, i8* %5
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 2
store i8 101, i8* %6
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 3
store i8 108, i8* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 4
store i8 108, i8* %8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 5
store i8 111, i8* %9
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 104, i8* %10
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
store i8 101, i8* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 2
store i8 108, i8* %12
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
store i8 108, i8* %13
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
store i8 111, i8* %14
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @String_Sub to i32 (i8*, i8*, i32, i32, ...)*)(i8* %15, i8* %4, i32 0, i32 2)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %15)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %10)
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @String_Length to i32 (i8*, ...)*)(i8* %4)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @String_Concat to i32 (i8*, i8*, ...)*)(i8* %4, i8* %10)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @String_Index to i32 (i8*, i8*, ...)*)(i8* %4, i8* %10)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %23)
ret i32 0
}