#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*/ exit(int);
char **malloc(int);
int /*<<< orphan*/ printf(char *, int);
char **mkargs(int argc, char *argv[]) {
  char **newargv;
  int len, i;
  len = argc * sizeof(char *);
  newargv = malloc(len);
  if (newargv == NULL) {
    printf("ucfront-env"
           ": failed to mallooc(%d)\n",
           len);
    exit(1);
  }
  for (i = 0; i < argc - 1; i++)
    newargv[i] = argv[i + 1];
  newargv[i] = NULL;
  return newargv;
}


x86 assembly (clang, -O0):
<mkargs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117a <mkargs+0x4a>
mov    -0x1c(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11bd <mkargs+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1181 <mkargs+0x51>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkargs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x0(,%rbx,8),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     119b <mkargs+0x5b>
mov    %rax,%r14
cmp    $0x2,%ebx
jl     1183 <mkargs+0x43>
add    $0xffffffff,%ebx
add    $0x8,%r15
lea    0x0(,%rbx,8),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
jmp    1185 <mkargs+0x45>
xor    %ebx,%ebx
movq   $0x0,(%r14,%rbx,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5e(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"ucfront-env: failed to mallooc(%d)\0A\00"
define i8** @mkargs(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i8** @malloc(i32 %12)
store i8** %13, i8*** %5
%14 = load i8**, i8*** %5
%15 = icmp eq i8** %14, null
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store i32 0, i32* %7
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load i8**, i8*** %4
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
br label %37
37: ; preds = %26
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %21
40: ; preds = %21
%41 = load i8**, i8*** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
store i8* null, i8** %44
%45 = load i8**, i8*** %5
ret i8** %45
}

LLVM IR (-O2):
@.str = [36 x i8] c"ucfront-env: failed to mallooc(%d)\0A\00"
define noalias i8** @mkargs(i32 %0, i8** nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call i8** @malloc(i32 %3)
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8** %4, null
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %20
9: ; preds = %7
%10 = add nsw i32 %0, -1
%11 = getelementptr i8*, i8** %1, i64 1
%12 = bitcast i8** %11 to i8*
%13 = zext i32 %10 to i64
%14 = shl nuw nsw i64 %13, 3
%15 = add nsw i32 %0, -1
%16 = zext i32 %15 to i64
br label %20
17: ; preds = %2
%18 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %3)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %9, %7
%21 = phi i64 [ 0, %7 ], [ %16, %9 ]
%22 = getelementptr inbounds i8*, i8** %4, i64 %21
store i8* null, i8** %22
ret i8** %4
}