void iterate_char_array() {
  char message[] = {'q', 'w', 'e', 'r', 't', 'y'};
  printf("iterate_char_array: %.*s\n", (int)sizeof(message), message);
  printf("result: ");
  for (int i = 0; i < sizeof(message) / sizeof(message[0]); ++i) {
    printf("%c", message[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<iterate_char_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xee2(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xedc(%rip),%ax
mov    %ax,-0x2(%rbp)
lea    -0x6(%rbp),%rdx
lea    0xecf(%rip),%rdi
mov    $0x6,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x6,%rax
jae    118b <iterate_char_array+0x7b>
movslq -0xc(%rbp),%rax
movsbl -0x6(%rbp,%rax,1),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <iterate_char_array+0x48>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate_char_array>:
push   %rax
movw   $0x7974,0x4(%rsp)
movl   $0x72657771,(%rsp)
lea    0xed0(%rip),%rdi
mov    %rsp,%rdx
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x1(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x2(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x3(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x4(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x5(%rsp),%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
pop    %rax
ret

LLVM IR (-O0):
@__const.iterate_char_array.message = [6 x i8] c"qwerty"
@.str = [26 x i8] c"iterate_char_array: %.*s\0A\00"
@.str.1 = [9 x i8] c"result: \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @iterate_char_array() {
%1 = alloca [6 x i8]
%2 = alloca i32
%3 = bitcast [6 x i8]* %1 to i8*
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 6, i8* %4)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 6
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %11
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %7
21: ; preds = %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.iterate_char_array.message = [6 x i8] c"qwerty"
@.str = [26 x i8] c"iterate_char_array: %.*s\0A\00"
@.str.1 = [9 x i8] c"result: \00"
define void @iterate_char_array() {
%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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 6, i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = call i32 @putchar(i32 %6)
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = call i32 @putchar(i32 %10)
%12 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i32 @putchar(i32 %14)
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = call i32 @putchar(i32 %18)
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 @putchar(i32 %22)
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 @putchar(i32 %26)
%28 = call i32 @putchar(i32 10)
ret void
}