#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 */
unsigned long ary_new();
int /*<<< orphan*/ ary_push(unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ define_global_variable(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ intern(char *);
int /*<<< orphan*/ string_new(char *);
void toi_set_argv(int argc, char **argv) {
  int i;
  unsigned long int ary = ary_new();
  for (i = 0; i < argc; i++)
    ary_push(ary, string_new(argv[i]));
  define_global_variable(intern("ARGV"), ary);
}


x86 assembly (clang, -O0):
<toi_set_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <ary_new@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11af <toi_set_argv+0x5f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <string_new@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1040 <ary_push@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <toi_set_argv+0x21>
lea    0xe4a(%rip),%rdi
call   1060 <intern@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
call   1050 <define_global_variable@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toi_set_argv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <ary_new@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    118c <toi_set_argv+0x3c>
mov    %ebp,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
call   1030 <string_new@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <ary_push@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <toi_set_argv+0x20>
lea    0xe6d(%rip),%rdi
call   1060 <intern@plt>
mov    %eax,%edi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <define_global_variable@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"ARGV\00"
define void @toi_set_argv(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i64 (...) @ary_new()
store i64 %7, i64* %6
store i32 0, i32* %5
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i64, i64* %6
%14 = load i8**, i8*** %4
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @string_new(i8* %18)
%20 = call i32 @ary_push(i64 %13, i32 %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %8
%25 = call i32 @intern(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%26 = load i64, i64* %6
%27 = call i32 @define_global_variable(i32 %25, i64 %26)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"ARGV\00"
define void @toi_set_argv(i32 %0, i8** nocapture %1) {
%3 = tail call i64 (...) @ary_new()
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @string_new(i8* %10)
%12 = tail call i32 @ary_push(i64 %3, i32 %11)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %2
%16 = tail call i32 @intern(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @define_global_variable(i32 %16, i64 %3)
ret void
}