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

/* Variables and functions */
double *arraylist_get(struct t_arraylist *, int);
int /*<<< orphan*/ arraylist_remove(struct t_arraylist *, int);
int arraylist_size(struct t_arraylist *);
double calc_pop_value(struct t_arraylist *list_values) {
  int size_values;
  double *ptr_value, value;
  if (!list_values)
    return 0;
  size_values = arraylist_size(list_values);
  if (size_values < 1)
    return 0;
  ptr_value = arraylist_get(list_values, size_values - 1);
  value = *ptr_value;
  arraylist_remove(list_values, size_values - 1);
  return value;
}


x86 assembly (clang, -O0):
<calc_pop_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <calc_pop_value+0x24>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b0 <calc_pop_value+0x80>
mov    -0x10(%rbp),%rdi
call   1050 <arraylist_size@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1177 <calc_pop_value+0x47>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b0 <calc_pop_value+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1040 <arraylist_get@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <arraylist_remove@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_pop_value>:
push   %rbp
push   %rbx
push   %rax
xorps  %xmm0,%xmm0
test   %rdi,%rdi
je     1171 <calc_pop_value+0x41>
mov    %rdi,%rbx
call   1050 <arraylist_size@plt>
xorps  %xmm0,%xmm0
test   %eax,%eax
jle    1171 <calc_pop_value+0x41>
mov    %eax,%ebp
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <arraylist_get@plt>
movsd  (%rax),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <arraylist_remove@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.t_arraylist = type { i32 }
define double @calc_pop_value(%struct.t_arraylist* %0) {
%2 = alloca double
%3 = alloca %struct.t_arraylist*
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
store %struct.t_arraylist* %0, %struct.t_arraylist** %3
%7 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%8 = icmp ne %struct.t_arraylist* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store double 0.000000e+00, double* %2
br label %28
10: ; preds = %1
%11 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%12 = call i32 @arraylist_size(%struct.t_arraylist* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %10
store double 0.000000e+00, double* %2
br label %28
16: ; preds = %10
%17 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = call double* @arraylist_get(%struct.t_arraylist* %17, i32 %19)
store double* %20, double** %5
%21 = load double*, double** %5
%22 = load double, double* %21
store double %22, double* %6
%23 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = call i32 @arraylist_remove(%struct.t_arraylist* %23, i32 %25)
%27 = load double, double* %6
store double %27, double* %2
br label %28
28: ; preds = %16, %15, %9
%29 = load double, double* %2
ret double %29
}

LLVM IR (-O2):
%struct.t_arraylist = type { i32 }
define double @calc_pop_value(%struct.t_arraylist* %0) {
%2 = icmp eq %struct.t_arraylist* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i32 @arraylist_size(%struct.t_arraylist* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = add nsw i32 %4, -1
%8 = tail call double* @arraylist_get(%struct.t_arraylist* %0, i32 %7)
%9 = load double, double* %8
%10 = tail call i32 @arraylist_remove(%struct.t_arraylist* %0, i32 %7)
br label %11
11: ; preds = %3, %1, %6
%12 = phi double [ %9, %6 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %3 ]
ret double %12
}