#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 */
struct list {
  int dummy;
};

/* Variables and functions */
struct list *createList();
int /*<<< orphan*/ insertFirst(struct list *, int);
struct list *createListFromArray(int *a, int sz) {
  struct list *result = createList();
  for (int i = sz - 1; i >= 0; --i)
    insertFirst(result, a[i]);
  return result;
}


x86 assembly (clang, -O0):
<createListFromArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <createList@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     116f <createListFromArray+0x4f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <insertFirst@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <createListFromArray+0x23>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createListFromArray>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <createList@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    1159 <createListFromArray+0x39>
mov    %ebp,%ebp
add    $0x1,%rbp
nopl   (%rax)
lea    -0x2(%rbp),%eax
mov    (%r14,%rax,4),%esi
mov    %rbx,%rdi
call   1030 <insertFirst@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1140 <createListFromArray+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.list = type { i32 }
define %struct.list* @createListFromArray(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.list*
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call %struct.list* (...) @createList()
store %struct.list* %7, %struct.list** %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %6
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %6
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load %struct.list*, %struct.list** %5
%15 = load i32*, i32** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @insertFirst(%struct.list* %14, i32 %19)
br label %21
21: ; preds = %13
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
br label %10
24: ; preds = %10
%25 = load %struct.list*, %struct.list** %5
ret %struct.list* %25
}

LLVM IR (-O2):
%struct.list = type { i32 }
define %struct.list* @createListFromArray(i32* nocapture %0, i32 %1) {
%3 = tail call %struct.list* (...) @createList()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %8, %2
ret %struct.list* %3
8: ; preds = %5, %8
%9 = phi i64 [ %6, %5 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 @insertFirst(%struct.list* %3, i32 %13)
%15 = icmp ugt i64 %9, 1
br i1 %15, label %8, label %7
}