#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 **malloc(int);
char **put_end_params(const char **argv, int argc) {
  char **list_args = malloc(sizeof(char *) * (argc + 1));
  int i;
  for (i = 0; i < argc; i++) {
    *(list_args + i) = (char *)*(argv + i);
  }
  *(list_args + argc) = NULL;
  return list_args;
}


x86 assembly (clang, -O0):
<put_end_params>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116f <put_end_params+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <put_end_params+0x2d>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_end_params>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r15
lea    0x8(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    114e <put_end_params+0x2e>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <memcpy@plt>
movslq %ebx,%rax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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