#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 */
char *dupstr(char *);
char **xmalloc(size_t);
char **duparr(char **array, size_t size) {
  char **dup;
  size_t i;
  dup = xmalloc((size + 2) * sizeof(char *));
  for (i = 0; i < size; ++i)
    dup[i] = dupstr(array[i]);
  dup[i + 1] = NULL;
  return dup;
}


x86 assembly (clang, -O0):
<duparr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
shl    $0x3,%rdi
call   1030 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118c <duparr+0x6c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <dupstr@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114d <duparr+0x2d>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movq   $0x0,0x8(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duparr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x10(,%rsi,8),%rdi
call   1030 <xmalloc@plt>
mov    %rax,%r14
test   %r12,%r12
je     116c <duparr+0x4c>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,8),%rdi
call   1040 <dupstr@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <duparr+0x30>
add    $0x1,%r12
jmp    1172 <duparr+0x52>
mov    $0x1,%r12d
movq   $0x0,(%r14,%r12,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @duparr(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64
store i8** %0, i8*** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = add i64 %7, 2
%9 = mul i64 %8, 8
%10 = call i8** @xmalloc(i64 %9)
store i8** %10, i8*** %5
store i64 0, i64* %6
br label %11
11: ; preds = %24, %2
%12 = load i64, i64* %6
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8**, i8*** %3
%17 = load i64, i64* %6
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
%19 = load i8*, i8** %18
%20 = call i8* @dupstr(i8* %19)
%21 = load i8**, i8*** %5
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
store i8* %20, i8** %23
br label %24
24: ; preds = %15
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %11
27: ; preds = %11
%28 = load i8**, i8*** %5
%29 = load i64, i64* %6
%30 = add i64 %29, 1
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
store i8* null, i8** %31
%32 = load i8**, i8*** %5
ret i8** %32
}

LLVM IR (-O2):
define i8** @duparr(i8** nocapture %0, i64 %1) {
%3 = shl i64 %1, 3
%4 = add i64 %3, 16
%5 = tail call i8** @xmalloc(i64 %4)
%6 = icmp eq i64 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %13, %7 ], [ 0, %2 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i8* @dupstr(i8* %10)
%12 = getelementptr inbounds i8*, i8** %5, i64 %8
store i8* %11, i8** %12
%13 = add nuw i64 %8, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = add i64 %1, 1
br label %17
17: ; preds = %15, %2
%18 = phi i64 [ 1, %2 ], [ %16, %15 ]
%19 = getelementptr inbounds i8*, i8** %5, i64 %18
store i8* null, i8** %19
ret i8** %5
}