void stringxy(char *string, int beginning, int end) {
  printf("\nString from (%i, %i) ", beginning, end);
  int i = 0;
  for (i = beginning; i <= end; i++) {
    printf("%c", (char *)string[i]);
  }
}


x86 assembly (clang, -O0):
<stringxy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1178 <stringxy+0x68>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbq (%rax,%rcx,1),%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <stringxy+0x33>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringxy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebx,%ebp
jg     1167 <stringxy+0x57>
movslq %ebp,%rax
add    %rax,%r14
sub    %ebp,%ebx
add    $0x1,%ebx
lea    0xed5(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbq (%r14,%rbp,1),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1150 <stringxy+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"\0AString from (%i, %i) \00"
@.str.1 = [3 x i8] c"%c\00"
define void @stringxy(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
store i32 0, i32* %7
%11 = load i32, i32* %5
store i32 %11, i32* %7
br label %12
12: ; preds = %25, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %16
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %12
28: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"\0AString from (%i, %i) \00"
@.str.1 = [3 x i8] c"%c\00"
define void @stringxy(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = icmp sgt i32 %1, %2
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = sext i32 %1 to i64
%8 = add i32 %2, 1
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ %7, %6 ], [ %16, %9 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = add nsw i64 %10, 1
%17 = trunc i64 %16 to i32
%18 = icmp eq i32 %8, %17
br i1 %18, label %19, label %9
19: ; preds = %9, %3
ret void
}