#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, char *);
void demo_string_array(void) {
  char str1[] = "hello world";
  char str2[] = "hello ";
  char str3[] = "world";
  char *list[3];
  list[0] = str1;
  list[1] = str2;
  list[2] = str3;
  int i;
  for (i = 0; i < 3; ++i) {
    printf("list[%d] = %s\n", i, list[i]);
  }
}


x86 assembly (clang, -O0):
<demo_string_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xedf(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    0xeda(%rip),%eax
mov    %eax,-0x13(%rbp)
mov    0xed4(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xecc(%rip),%al
mov    %al,-0xd(%rbp)
mov    0xeb7(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xeb1(%rip),%ax
mov    %ax,-0x15(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x13(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x19(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    11ac <demo_string_array+0x9c>
mov    -0x44(%rbp),%esi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdx
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    117c <demo_string_array+0x6c>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demo_string_array>:
push   %rbx
sub    $0x20,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,0x10(%rsp)
movl   $0x646c72,0x18(%rsp)
movl   $0x206f6c,0xb(%rsp)
movl   $0x6c6c6568,0x8(%rsp)
6c
movw   $0x64,0x4(%rsp)
movl   $0x6c726f77,(%rsp)
lea    0xec2(%rip),%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.demo_string_array.str1 = [12 x i8] c"hello world\00"
@__const.demo_string_array.str2 = [7 x i8] c"hello \00"
@__const.demo_string_array.str3 = [6 x i8] c"world\00"
@.str = [15 x i8] c"list[%d] = %s\0A\00"
define void @demo_string_array() {
%1 = alloca [12 x i8]
%2 = alloca [7 x i8]
%3 = alloca [6 x i8]
%4 = alloca [3 x i8*]
%5 = alloca i32
%6 = bitcast [12 x i8]* %1 to i8*
%7 = bitcast [7 x i8]* %2 to i8*
%8 = bitcast [6 x i8]* %3 to i8*
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
store i8* %9, i8** %10
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
store i8* %11, i8** %12
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
store i8* %13, i8** %14
store i32 0, i32* %5
br label %15
15: ; preds = %25, %0
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
ret void
}

LLVM IR (-O2):
@__const.demo_string_array.str1 = [12 x i8] c"hello world\00"
@__const.demo_string_array.str2 = [7 x i8] c"hello \00"
@__const.demo_string_array.str3 = [6 x i8] c"world\00"
@.str = [15 x i8] c"list[%d] = %s\0A\00"
define void @demo_string_array() {
%1 = alloca [12 x i8]
%2 = alloca [7 x i8]
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 0, i8* %4)
%8 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 1, i8* %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 2, i8* %6)
ret void
}