#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 */
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char **realloc(char **, int);
int main() {
  int i;
  char **pa;
  pa = malloc(sizeof(char *) * 2);
  pa[0] = malloc(sizeof(char) * 3);
  pa[0] = "hi";
  pa[1] = malloc(sizeof(char) * 4);
  pa[1] = "bye";
  pa = realloc(pa, sizeof(char *) * 3);
  pa[2] = malloc(sizeof(char) * 6);
  pa[2] = "again";
  printf("pa[0] = [%s]\n", pa[0]);
  printf("pa[1] = [%s]\n", pa[1]);
  printf("pa[2] = [%s]\n", pa[2]);
  printf("Disposition of chars in pa[0] = ");
  for (i = 0; i < 4; ++i) {
    printf("[%d]", (int)pa[0][i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
lea    0xe94(%rip),%rcx
mov    %rcx,(%rax)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
lea    0xe74(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x18,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
lea    0xe42(%rip),%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1254 <main+0x124>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    121f <main+0xef>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x10,%edi
call   1050 <malloc@plt>
lea    0xeab(%rip),%rcx
mov    %rcx,(%rax)
lea    0xea4(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    %rax,%rdi
mov    $0x18,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
lea    0xe8d(%rip),%rax
mov    %rax,0x10(%rbx)
mov    (%rbx),%rsi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
movsbl (%rax),%esi
lea    0xe8a(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
movsbl 0x1(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
movsbl 0x2(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rax
movsbl 0x3(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"hi\00"
@.str.1 = [4 x i8] c"bye\00"
@.str.2 = [6 x i8] c"again\00"
@.str.3 = [14 x i8] c"pa[0] = [%s]\0A\00"
@.str.4 = [14 x i8] c"pa[1] = [%s]\0A\00"
@.str.5 = [14 x i8] c"pa[2] = [%s]\0A\00"
@.str.6 = [33 x i8] c"Disposition of chars in pa[0] = \00"
@.str.7 = [5 x i8] c"[%d]\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8**
store i32 0, i32* %1
%4 = call i8* @malloc(i32 16)
%5 = bitcast i8* %4 to i8**
store i8** %5, i8*** %3
%6 = call i8* @malloc(i32 3)
%7 = load i8**, i8*** %3
%8 = getelementptr inbounds i8*, i8** %7, i64 0
store i8* %6, i8** %8
%9 = load i8**, i8*** %3
%10 = getelementptr inbounds i8*, i8** %9, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = call i8* @malloc(i32 4)
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* %11, i8** %13
%14 = load i8**, i8*** %3
%15 = getelementptr inbounds i8*, i8** %14, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = load i8**, i8*** %3
%17 = call i8** @realloc(i8** %16, i32 24)
store i8** %17, i8*** %3
%18 = call i8* @malloc(i32 6)
%19 = load i8**, i8*** %3
%20 = getelementptr inbounds i8*, i8** %19, i64 2
store i8* %18, i8** %20
%21 = load i8**, i8*** %3
%22 = getelementptr inbounds i8*, i8** %21, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %22
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %3
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i8**, i8*** %3
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %36
36: ; preds = %49, %0
%37 = load i32, i32* %2
%38 = icmp slt i32 %37, 4
br i1 %38, label %39, label %52
39: ; preds = %36
%40 = load i8**, i8*** %3
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %39
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %36
52: ; preds = %36
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"hi\00"
@.str.1 = [4 x i8] c"bye\00"
@.str.2 = [6 x i8] c"again\00"
@.str.3 = [14 x i8] c"pa[0] = [%s]\0A\00"
@.str.4 = [14 x i8] c"pa[1] = [%s]\0A\00"
@.str.5 = [14 x i8] c"pa[2] = [%s]\0A\00"
@.str.6 = [33 x i8] c"Disposition of chars in pa[0] = \00"
@.str.7 = [5 x i8] c"[%d]\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%2 = bitcast i8* %1 to i8**
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = getelementptr inbounds i8*, i8** %2, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %3
%4 = tail call i8** @realloc(i8** %2, i32 24)
%5 = getelementptr inbounds i8*, i8** %4, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds i8*, i8** %4, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%33 = tail call i32 @putchar(i32 10)
ret i32 0
}