void strings_with_constant_indices() {
  printf("%c\n", "vec"[1]);
  printf("%c\n", 1 ["vec"]);
  int i = 2;
  printf("%c\n", "vec"[--i]);
  printf("%c\n", (--i)["vec"]);
}


x86 assembly (clang, -O0):
<strings_with_constant_indices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsbl 0xee6(%rip),%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl 0xed1(%rip),%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
movslq %eax,%rcx
lea    0xea8(%rip),%rax
movsbl (%rax,%rcx,1),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
movslq %eax,%rcx
lea    0xe83(%rip),%rax
movsbl (%rax,%rcx,1),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_with_constant_indices>:
push   %rbx
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x76,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%c\0A\00"
define void @strings_with_constant_indices() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 101)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 101)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 101)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 118)
ret void
}