#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;
};
typedef int /*<<< orphan*/ result;

/* Variables and functions */
int /*<<< orphan*/ arraylist_add(struct t_arraylist *, double *);
char *arraylist_get(struct t_arraylist *, int);
int /*<<< orphan*/ arraylist_remove(struct t_arraylist *, int);
int arraylist_size(struct t_arraylist *);
double calc_operation(char *, double, double);
double calc_pop_value(struct t_arraylist *);
double *malloc(int);
void calc_operation_stacks(struct t_arraylist *list_values,
                           struct t_arraylist *list_ops) {
  int size_ops;
  double value1, value2, result, *ptr_result;
  char *ptr_operator;
  if (!list_values || !list_ops)
    return;
  size_ops = arraylist_size(list_ops);
  if (size_ops < 1)
    return;
  ptr_operator = arraylist_get(list_ops, size_ops - 1);
  value2 = calc_pop_value(list_values);
  value1 = calc_pop_value(list_values);
  result = calc_operation(ptr_operator, value1, value2);
  ptr_result = malloc(sizeof(result));
  *ptr_result = result;
  arraylist_add(list_values, ptr_result);
  arraylist_remove(list_ops, size_ops - 1);
}


x86 assembly (clang, -O0):
<calc_operation_stacks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1196 <calc_operation_stacks+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    119b <calc_operation_stacks+0x2b>
jmp    1234 <calc_operation_stacks+0xc4>
mov    -0x10(%rbp),%rdi
call   1090 <arraylist_size@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11b6 <calc_operation_stacks+0x46>
jmp    1234 <calc_operation_stacks+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1070 <arraylist_get@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <calc_pop_value@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <calc_pop_value@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <calc_operation@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <arraylist_add@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1060 <arraylist_remove@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_operation_stacks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1202 <calc_operation_stacks+0x92>
mov    %rsi,%r14
test   %rsi,%rsi
je     1202 <calc_operation_stacks+0x92>
mov    %rdi,%rbx
mov    %r14,%rdi
call   1090 <arraylist_size@plt>
test   %eax,%eax
jle    1202 <calc_operation_stacks+0x92>
mov    %eax,%ebp
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <arraylist_get@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <calc_pop_value@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1040 <calc_pop_value@plt>
mov    %r15,%rdi
movsd  (%rsp),%xmm1
call   1030 <calc_operation@plt>
movsd  %xmm0,(%rsp)
mov    $0x8,%edi
call   1050 <malloc@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <arraylist_add@plt>
mov    %r14,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <arraylist_remove@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.t_arraylist = type { i32 }
define void @calc_operation_stacks(%struct.t_arraylist* %0, %struct.t_arraylist* %1) {
%3 = alloca %struct.t_arraylist*
%4 = alloca %struct.t_arraylist*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca i8*
store %struct.t_arraylist* %0, %struct.t_arraylist** %3
store %struct.t_arraylist* %1, %struct.t_arraylist** %4
%11 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%12 = icmp ne %struct.t_arraylist* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load %struct.t_arraylist*, %struct.t_arraylist** %4
%15 = icmp ne %struct.t_arraylist* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %2
br label %46
17: ; preds = %13
%18 = load %struct.t_arraylist*, %struct.t_arraylist** %4
%19 = call i32 @arraylist_size(%struct.t_arraylist* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %17
br label %46
23: ; preds = %17
%24 = load %struct.t_arraylist*, %struct.t_arraylist** %4
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = call i8* @arraylist_get(%struct.t_arraylist* %24, i32 %26)
store i8* %27, i8** %10
%28 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%29 = call double @calc_pop_value(%struct.t_arraylist* %28)
store double %29, double* %7
%30 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%31 = call double @calc_pop_value(%struct.t_arraylist* %30)
store double %31, double* %6
%32 = load i8*, i8** %10
%33 = load double, double* %6
%34 = load double, double* %7
%35 = call double @calc_operation(i8* %32, double %33, double %34)
store double %35, double* %8
%36 = call double* @malloc(i32 8)
store double* %36, double** %9
%37 = load double, double* %8
%38 = load double*, double** %9
store double %37, double* %38
%39 = load %struct.t_arraylist*, %struct.t_arraylist** %3
%40 = load double*, double** %9
%41 = call i32 @arraylist_add(%struct.t_arraylist* %39, double* %40)
%42 = load %struct.t_arraylist*, %struct.t_arraylist** %4
%43 = load i32, i32* %5
%44 = sub nsw i32 %43, 1
%45 = call i32 @arraylist_remove(%struct.t_arraylist* %42, i32 %44)
br label %46
46: ; preds = %23, %22, %16
ret void
}

LLVM IR (-O2):
%struct.t_arraylist = type { i32 }
define void @calc_operation_stacks(%struct.t_arraylist* %0, %struct.t_arraylist* %1) {
%3 = icmp ne %struct.t_arraylist* %0, null
%4 = icmp ne %struct.t_arraylist* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = tail call i32 @arraylist_size(%struct.t_arraylist* %1)
%8 = icmp slt i32 %7, 1
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = add nsw i32 %7, -1
%11 = tail call i8* @arraylist_get(%struct.t_arraylist* %1, i32 %10)
%12 = tail call double @calc_pop_value(%struct.t_arraylist* %0)
%13 = tail call double @calc_pop_value(%struct.t_arraylist* %0)
%14 = tail call double @calc_operation(i8* %11, double %13, double %12)
%15 = tail call double* @malloc(i32 8)
store double %14, double* %15
%16 = tail call i32 @arraylist_add(%struct.t_arraylist* %0, double* %15)
%17 = tail call i32 @arraylist_remove(%struct.t_arraylist* %1, i32 %10)
br label %18
18: ; preds = %6, %2, %9
ret void
}