#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*/ free(char **);
void *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char **push_str(char **arr, char *str, int size) {
  char **newarr = malloc(sizeof(char *) * (size + 1));
  int i;
  newarr[0] = malloc(sizeof(char) * strlen(str));
  strcpy(newarr[0], str);
  for (i = 0; i < size; i++)
    newarr[i + 1] = arr[i];
  free(arr);
  return newarr;
}


x86 assembly (clang, -O0):
<push_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <push_str+0x98>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <push_str+0x61>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<push_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x8(,%rbx,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
test   %ebx,%ebx
jle    11a5 <push_str+0x55>
mov    %r15,%rdi
add    $0x8,%rdi
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r14,%rsi
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @push_str(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
%15 = bitcast i8* %14 to i8**
store i8** %15, i8*** %7
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds i8*, i8** %22, i64 0
store i8* %21, i8** %23
%24 = load i8**, i8*** %7
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
store i32 0, i32* %8
br label %29
29: ; preds = %44, %3
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = load i8**, i8*** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %7
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
store i8* %38, i8** %43
br label %44
44: ; preds = %33
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %29
47: ; preds = %29
%48 = load i8**, i8*** %4
%49 = call i32 @free(i8** %48)
%50 = load i8**, i8*** %7
ret i8** %50
}

LLVM IR (-O2):
define noalias i8** @push_str(i8** nocapture %0, i8* %1, i32 %2) {
%4 = shl i32 %2, 3
%5 = add i32 %4, 8
%6 = tail call i8* @malloc(i32 %5)
%7 = bitcast i8* %6 to i8**
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i8* @malloc(i32 %8)
store i8* %9, i8** %7
%10 = tail call i32 @strcpy(i8* %9, i8* %1)
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = bitcast i8** %0 to i8*
%14 = getelementptr i8, i8* %6, i64 8
%15 = zext i32 %2 to i64
%16 = shl nuw nsw i64 %15, 3
br label %17
17: ; preds = %12, %3
%18 = tail call i32 @free(i8** %0)
ret i8** %7
}