int main(void) {
  char buf[6];
  strcpy(buf, "foobar");
  printf("       buf == '%s'\n", buf);
  printf("*(buf + 4) == '%c'\n", *(4 + buf));
  printf("    buf[4] == '%c'\n", buf[4]);
  printf("    4[buf] == '%c'\n", 4 [buf]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xa(%rbp),%rdi
lea    0xec6(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa(%rbp),%rsi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x6(%rbp),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x6(%rbp),%esi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x6(%rbp),%esi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x726162,0x3(%rsp)
movl   $0x626f6f66,(%rsp)
lea    0xee0(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl 0x4(%rsp),%esi
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl 0x4(%rsp),%esi
lea    0xedf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl 0x4(%rsp),%esi
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"foobar\00"
@.str.1 = [20 x i8] c" buf == '%s'\0A\00"
@.str.2 = [20 x i8] c"*(buf + 4) == '%c'\0A\00"
@.str.3 = [20 x i8] c" buf[4] == '%c'\0A\00"
@.str.4 = [20 x i8] c" 4[buf] == '%c'\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 4
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %12)
ret i32 0
}