#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
char **malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char **v;
  char str[80];
  int i, pos;
  v = malloc(3 * sizeof(char *));
  while (1) {
    for (i = 0; i < 3; i++) {
      printf("[%d] ", i + 1);
      if (v[i] == NULL)
        printf("(vazio)\n");
      else
        printf("%s\n", v[i]);
    }
    do {
      printf("Posicao para nova string (1 a %d): ", 3);
      scanf("%d", &pos);
      getchar();
    } while (pos < 0 || pos > 3);
    if (pos == 0)
      break;
    printf("Nova String: ");
    fgets(str, 80, stdin);
    str[strlen(str) - 1] = '\0';
    v[pos - 1] = realloc(v[pos - 1], strlen(str));
    strcpy(v[pos - 1], str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x3,-0x64(%rbp)
jge    1218 <main+0x98>
mov    -0x64(%rbp),%esi
add    $0x1,%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11eb <main+0x6b>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1205 <main+0x85>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120a <main+0x8a>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11a7 <main+0x27>
jmp    121d <main+0x9d>
lea    0xdef(%rip),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe00(%rip),%rdi
lea    -0x68(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    $0x1,%al
cmpl   $0x0,-0x68(%rbp)
mov    %al,-0x69(%rbp)
jl     1260 <main+0xe0>
cmpl   $0x3,-0x68(%rbp)
setg   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    121d <main+0x9d>
cmpl   $0x0,-0x68(%rbp)
jne    127a <main+0xfa>
jmp    130e <main+0x18e>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x68(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11a0 <main+0x20>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    $0x18,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe4e(%rip),%r14
lea    0xe4d(%rip),%r13
lea    0xe6a(%rip),%rbx
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%rdi
test   %rdi,%rdi
jne    11ee <main+0x5e>
lea    0xe4d(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r15),%rdi
test   %rdi,%rdi
jne    1212 <main+0x82>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r15),%rdi
test   %rdi,%rdi
jne    1236 <main+0xa6>
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
ja     1240 <main+0xb0>
test   %eax,%eax
je     12e5 <main+0x155>
lea    0xdb8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x50,%esi
call   1070 <fgets@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r12,%rdi
movslq 0xc(%rsp),%rax
mov    %r14,%r12
mov    -0x8(%r15,%rax,8),%r14
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %r12,%r14
mov    %eax,%esi
call   10a0 <realloc@plt>
movslq 0xc(%rsp),%rcx
mov    %rax,-0x8(%r15,%rcx,8)
mov    %rax,%rdi
lea    0x10(%rsp),%rsi
call   1030 <strcpy@plt>
jmp    11d0 <main+0x40>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"[%d] \00"
@.str.1 = [9 x i8] c"(vazio)\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [36 x i8] c"Posicao para nova string (1 a %d): \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [14 x i8] c"Nova String: \00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i8** @malloc(i32 24)
store i8** %6, i8*** %2
br label %7
7: ; preds = %0, %51
store i32 0, i32* %4
br label %8
8: ; preds = %31, %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8**, i8*** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %30
23: ; preds = %11
%24 = load i8**, i8*** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %23, %21
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %8
34: ; preds = %8
br label %35
35: ; preds = %45, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 3)
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%38 = call i32 (...) @getchar()
br label %39
39: ; preds = %35
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %5
%44 = icmp sgt i32 %43, 3
br label %45
45: ; preds = %42, %39
%46 = phi i1 [ true, %39 ], [ %44, %42 ]
br i1 %46, label %35, label %47
47: ; preds = %45
%48 = load i32, i32* %5
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
br label %83
51: ; preds = %47
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %53, i32 80, i32 %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %59
store i8 0, i8* %60
%61 = load i8**, i8*** %2
%62 = load i32, i32* %5
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %61, i64 %64
%66 = load i8*, i8** %65
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = call i8* @realloc(i8* %66, i32 %68)
%70 = load i8**, i8*** %2
%71 = load i32, i32* %5
%72 = sub nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %70, i64 %73
store i8* %69, i8** %74
%75 = load i8**, i8*** %2
%76 = load i32, i32* %5
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %75, i64 %78
%80 = load i8*, i8** %79
%81 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%82 = call i32 @strcpy(i8* %80, i8* %81)
br label %7
83: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"[%d] \00"
@.str.3 = [36 x i8] c"Posicao para nova string (1 a %d): \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [14 x i8] c"Nova String: \00"
@stdin = global i32 0
@str = [8 x i8] c"(vazio)\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i8** @malloc(i32 24)
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = getelementptr inbounds i8*, i8** %5, i64 2
br label %8
8: ; preds = %41, %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %16
14: ; preds = %8
%15 = call i32 @puts(i8* %10)
br label %16
16: ; preds = %12, %14
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2)
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* %18)
br label %24
22: ; preds = %16
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 3)
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @puts(i8* %26)
br label %32
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
br label %33
33: ; preds = %32, %33
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 3)
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%36 = call i32 (...) @getchar()
%37 = load i32, i32* %2
%38 = icmp ugt i32 %37, 3
br i1 %38, label %33, label %39
39: ; preds = %33
%40 = icmp eq i32 %37, 0
br i1 %40, label %61, label %41
41: ; preds = %39
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %3, i32 80, i32 %43)
%45 = call i32 @strlen(i8* %3)
%46 = add nsw i32 %45, -1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* %2
%50 = add nsw i32 %49, -1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %5, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @strlen(i8* %3)
%55 = call i8* @realloc(i8* %53, i32 %54)
%56 = load i32, i32* %2
%57 = add nsw i32 %56, -1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %5, i64 %58
store i8* %55, i8** %59
%60 = call i32 @strcpy(i8* %55, i8* %3)
br label %8
61: ; preds = %39
ret i32 0
}