#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*/ memcpy(char *, void const *, int);
void *realloc(void *, int);
int /*<<< orphan*/ sensors_fatal_error(char *, char *);
void sensors_add_array_el(const void *el, void *list, int *num_el, int *max_el,
                          int el_size) {
  int new_max_el;
  void **my_list = (void *)list;
  if (*num_el + 1 > *max_el) {
    new_max_el = *max_el + 16;
    *my_list = realloc(*my_list, new_max_el * el_size);
    if (!*my_list)
      sensors_fatal_error("sensors_add_array_el", "Allocating new elements");
    *max_el = new_max_el;
  }
  memcpy(((char *)*my_list) + *num_el * el_size, el, el_size);
  (*num_el)++;
}


x86 assembly (clang, -O0):
<sensors_add_array_el>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jle    11bc <sensors_add_array_el+0x8c>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%esi
imul   -0x24(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b3 <sensors_add_array_el+0x83>
lea    0xe59(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1030 <sensors_fatal_error@plt>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
imul   -0x24(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensors_add_array_el>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdx),%eax
mov    (%rcx),%ebx
cmp    %ebx,%eax
jl     1185 <sensors_add_array_el+0x55>
mov    %rcx,%r12
add    $0x10,%ebx
mov    (%r15),%rdi
mov    %ebx,%esi
imul   %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
jne    117d <sensors_add_array_el+0x4d>
lea    0xe8f(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <sensors_fatal_error@plt>
mov    %ebx,(%r12)
mov    0x0(%r13),%eax
imul   %ebp,%eax
movslq %eax,%rdi
add    (%r15),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
addl   $0x1,0x0(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"sensors_add_array_el\00"
@.str.1 = [24 x i8] c"Allocating new elements\00"
define void @sensors_add_array_el(i8* %0, i8* %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8**
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%13 = load i8*, i8** %7
%14 = bitcast i8* %13 to i8**
store i8** %14, i8*** %12
%15 = load i32*, i32** %8
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = load i32*, i32** %9
%19 = load i32, i32* %18
%20 = icmp sgt i32 %17, %19
br i1 %20, label %21, label %40
21: ; preds = %5
%22 = load i32*, i32** %9
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 16
store i32 %24, i32* %11
%25 = load i8**, i8*** %12
%26 = load i8*, i8** %25
%27 = load i32, i32* %11
%28 = load i32, i32* %10
%29 = mul nsw i32 %27, %28
%30 = call i8* @realloc(i8* %26, i32 %29)
%31 = load i8**, i8*** %12
store i8* %30, i8** %31
%32 = load i8**, i8*** %12
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %21
%36 = call i32 @sensors_fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %21
%38 = load i32, i32* %11
%39 = load i32*, i32** %9
store i32 %38, i32* %39
br label %40
40: ; preds = %37, %5
%41 = load i8**, i8*** %12
%42 = load i8*, i8** %41
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = load i32, i32* %10
%46 = mul nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %42, i64 %47
%49 = load i8*, i8** %6
%50 = load i32, i32* %10
%51 = call i32 @memcpy(i8* %48, i8* %49, i32 %50)
%52 = load i32*, i32** %8
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"sensors_add_array_el\00"
@.str.1 = [24 x i8] c"Allocating new elements\00"
define void @sensors_add_array_el(i8* %0, i8* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32 %4) {
%6 = bitcast i8* %1 to i8**
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %5
%11 = add nsw i32 %8, 16
%12 = load i8*, i8** %6
%13 = mul nsw i32 %11, %4
%14 = tail call i8* @realloc(i8* %12, i32 %13)
store i8* %14, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @sensors_fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
store i32 %11, i32* %3
%19 = load i32, i32* %2
br label %20
20: ; preds = %18, %5
%21 = phi i32 [ %19, %18 ], [ %7, %5 ]
%22 = load i8*, i8** %6
%23 = mul nsw i32 %21, %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = tail call i32 @memcpy(i8* %25, i8* %0, i32 %4)
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
ret void
}