#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 llist {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append_element(struct llist *, void *);
struct llist *create_llist();
struct llist *array_to_llist(void **array, int count) {
  struct llist *list = create_llist();
  if (NULL == list)
    return NULL;
  int i;
  for (i = 0; i < count; i++)
    if (!append_element(list, array[i]))
      return NULL;
  return list;
}


x86 assembly (clang, -O0):
<array_to_llist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1040 <create_llist@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1153 <array_to_llist+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11ac <array_to_llist+0x8c>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a4 <array_to_llist+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <append_element@plt>
cmp    $0x0,%eax
jne    1191 <array_to_llist+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11ac <array_to_llist+0x8c>
jmp    1196 <array_to_llist+0x76>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <array_to_llist+0x3a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_to_llist>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <create_llist@plt>
test   %rax,%rax
je     116b <array_to_llist+0x4b>
mov    %rax,%rbx
test   %ebp,%ebp
jle    116d <array_to_llist+0x4d>
mov    %ebp,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1030 <append_element@plt>
test   %eax,%eax
je     116b <array_to_llist+0x4b>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <array_to_llist+0x30>
jmp    116d <array_to_llist+0x4d>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.llist = type { i32 }
define %struct.llist* @array_to_llist(i8** nocapture %0, i32 %1) {
%3 = tail call %struct.llist* (...) @create_llist()
%4 = icmp eq %struct.llist* %3, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %5
%8 = zext i32 %1 to i64
br label %11
9: ; preds = %11
%10 = icmp eq i64 %17, %8
br i1 %10, label %18, label %11
11: ; preds = %7, %9
%12 = phi i64 [ 0, %7 ], [ %17, %9 ]
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @append_element(%struct.llist* %3, i8* %14)
%16 = icmp eq i32 %15, 0
%17 = add nuw nsw i64 %12, 1
br i1 %16, label %18, label %9
18: ; preds = %9, %11, %5, %2
%19 = phi %struct.llist* [ null, %2 ], [ %3, %5 ], [ %3, %9 ], [ null, %11 ]
ret %struct.llist* %19
}