#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*/ get_var(char const *, size_t, char *);
int /*<<< orphan*/ printf(char *, unsigned long long);
unsigned long long strtoull(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
void f_maxmemory(const char *buffer, size_t len) {
  unsigned long long tmp_table_size;
  unsigned long long max_heap_table_size;
  unsigned long long max_tmp_table_size;
  unsigned long long server_buffers;
  unsigned long long per_thread_buffers;
  unsigned long long total_per_thread_buffers;
  tmp_table_size = strtoull(get_var(buffer, len, "tmp_table_size"), NULL, 10);
  max_heap_table_size =
      strtoull(get_var(buffer, len, "max_heap_table_size"), NULL, 10);
  max_tmp_table_size = (tmp_table_size > max_heap_table_size)
                           ? max_heap_table_size
                           : tmp_table_size;
  server_buffers = strtoull(get_var(buffer, len, "key_buffer_size"), NULL, 10) +
                   max_tmp_table_size;
  server_buffers +=
      strtoull(get_var(buffer, len, "innodb_buffer_pool_size"), NULL, 10);
  server_buffers += strtoull(
      get_var(buffer, len, "innodb_additional_mem_pool_size"), NULL, 10);
  server_buffers +=
      strtoull(get_var(buffer, len, "innodb_log_buffer_size"), NULL, 10);
  server_buffers +=
      strtoull(get_var(buffer, len, "query_cache_size"), NULL, 10);
  per_thread_buffers =
      strtoull(get_var(buffer, len, "read_buffer_size"), NULL, 10);
  per_thread_buffers +=
      strtoull(get_var(buffer, len, "read_rnd_buffer_size"), NULL, 10);
  per_thread_buffers +=
      strtoull(get_var(buffer, len, "sort_buffer_size"), NULL, 10);
  per_thread_buffers +=
      strtoull(get_var(buffer, len, "thread_stack"), NULL, 10);
  per_thread_buffers +=
      strtoull(get_var(buffer, len, "join_buffer_size"), NULL, 10);
  total_per_thread_buffers =
      per_thread_buffers *
      strtoull(get_var(buffer, len, "max_connections"), NULL, 10);
  printf("%llu", server_buffers + total_per_thread_buffers);
}


x86 assembly (clang, -O0):
<f_maxmemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xeb1(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11ab <f_maxmemory+0x7b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11b3 <f_maxmemory+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe1d(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdd6(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdbf(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xda4(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xd85(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xd62(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rsi
add    -0x40(%rbp),%rsi
lea    0xd3f(%rip),%rdi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_maxmemory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xebb(%rip),%rdx
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,%r12
lea    0xead(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
cmp    %rax,%r12
cmova  %rax,%r12
lea    0xe9a(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%r12
lea    0xe87(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%r12
lea    0xe7c(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%r12
lea    0xe79(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%r12
lea    0xe6d(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%r12
lea    0xe5b(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%rbx
lea    0xe3b(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%rbx
lea    0xe29(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%rbx
lea    0xe13(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
add    %rax,%rbx
lea    0xe01(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <get_var@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
imul   %rax,%rbx
add    %r12,%rbx
lea    0xdea(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"tmp_table_size\00"
@.str.1 = [20 x i8] c"max_heap_table_size\00"
@.str.2 = [16 x i8] c"key_buffer_size\00"
@.str.3 = [24 x i8] c"innodb_buffer_pool_size\00"
@.str.4 = [32 x i8] c"innodb_additional_mem_pool_size\00"
@.str.5 = [23 x i8] c"innodb_log_buffer_size\00"
@.str.6 = [17 x i8] c"query_cache_size\00"
@.str.7 = [17 x i8] c"read_buffer_size\00"
@.str.8 = [21 x i8] c"read_rnd_buffer_size\00"
@.str.9 = [17 x i8] c"sort_buffer_size\00"
@.str.10 = [13 x i8] c"thread_stack\00"
@.str.11 = [17 x i8] c"join_buffer_size\00"
@.str.12 = [16 x i8] c"max_connections\00"
@.str.13 = [5 x i8] c"%llu\00"
define void @f_maxmemory(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = call i32 @get_var(i8* %11, i64 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @strtoull(i32 %13, i32* null, i32 10)
store i64 %14, i64* %5
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = call i32 @get_var(i8* %15, i64 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = call i64 @strtoull(i32 %17, i32* null, i32 10)
store i64 %18, i64* %6
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = icmp ugt i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = load i64, i64* %6
br label %26
24: ; preds = %2
%25 = load i64, i64* %5
br label %26
26: ; preds = %24, %22
%27 = phi i64 [ %23, %22 ], [ %25, %24 ]
store i64 %27, i64* %7
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = call i32 @get_var(i8* %28, i64 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = call i64 @strtoull(i32 %30, i32* null, i32 10)
%32 = load i64, i64* %7
%33 = add i64 %31, %32
store i64 %33, i64* %8
%34 = load i8*, i8** %3
%35 = load i64, i64* %4
%36 = call i32 @get_var(i8* %34, i64 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%37 = call i64 @strtoull(i32 %36, i32* null, i32 10)
%38 = load i64, i64* %8
%39 = add i64 %38, %37
store i64 %39, i64* %8
%40 = load i8*, i8** %3
%41 = load i64, i64* %4
%42 = call i32 @get_var(i8* %40, i64 %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%43 = call i64 @strtoull(i32 %42, i32* null, i32 10)
%44 = load i64, i64* %8
%45 = add i64 %44, %43
store i64 %45, i64* %8
%46 = load i8*, i8** %3
%47 = load i64, i64* %4
%48 = call i32 @get_var(i8* %46, i64 %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%49 = call i64 @strtoull(i32 %48, i32* null, i32 10)
%50 = load i64, i64* %8
%51 = add i64 %50, %49
store i64 %51, i64* %8
%52 = load i8*, i8** %3
%53 = load i64, i64* %4
%54 = call i32 @get_var(i8* %52, i64 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%55 = call i64 @strtoull(i32 %54, i32* null, i32 10)
%56 = load i64, i64* %8
%57 = add i64 %56, %55
store i64 %57, i64* %8
%58 = load i8*, i8** %3
%59 = load i64, i64* %4
%60 = call i32 @get_var(i8* %58, i64 %59, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%61 = call i64 @strtoull(i32 %60, i32* null, i32 10)
store i64 %61, i64* %9
%62 = load i8*, i8** %3
%63 = load i64, i64* %4
%64 = call i32 @get_var(i8* %62, i64 %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%65 = call i64 @strtoull(i32 %64, i32* null, i32 10)
%66 = load i64, i64* %9
%67 = add i64 %66, %65
store i64 %67, i64* %9
%68 = load i8*, i8** %3
%69 = load i64, i64* %4
%70 = call i32 @get_var(i8* %68, i64 %69, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%71 = call i64 @strtoull(i32 %70, i32* null, i32 10)
%72 = load i64, i64* %9
%73 = add i64 %72, %71
store i64 %73, i64* %9
%74 = load i8*, i8** %3
%75 = load i64, i64* %4
%76 = call i32 @get_var(i8* %74, i64 %75, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%77 = call i64 @strtoull(i32 %76, i32* null, i32 10)
%78 = load i64, i64* %9
%79 = add i64 %78, %77
store i64 %79, i64* %9
%80 = load i8*, i8** %3
%81 = load i64, i64* %4
%82 = call i32 @get_var(i8* %80, i64 %81, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%83 = call i64 @strtoull(i32 %82, i32* null, i32 10)
%84 = load i64, i64* %9
%85 = add i64 %84, %83
store i64 %85, i64* %9
%86 = load i64, i64* %9
%87 = load i8*, i8** %3
%88 = load i64, i64* %4
%89 = call i32 @get_var(i8* %87, i64 %88, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%90 = call i64 @strtoull(i32 %89, i32* null, i32 10)
%91 = mul i64 %86, %90
store i64 %91, i64* %10
%92 = load i64, i64* %8
%93 = load i64, i64* %10
%94 = add i64 %92, %93
%95 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64 %94)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"tmp_table_size\00"
@.str.1 = [20 x i8] c"max_heap_table_size\00"
@.str.2 = [16 x i8] c"key_buffer_size\00"
@.str.3 = [24 x i8] c"innodb_buffer_pool_size\00"
@.str.4 = [32 x i8] c"innodb_additional_mem_pool_size\00"
@.str.5 = [23 x i8] c"innodb_log_buffer_size\00"
@.str.6 = [17 x i8] c"query_cache_size\00"
@.str.7 = [17 x i8] c"read_buffer_size\00"
@.str.8 = [21 x i8] c"read_rnd_buffer_size\00"
@.str.9 = [17 x i8] c"sort_buffer_size\00"
@.str.10 = [13 x i8] c"thread_stack\00"
@.str.11 = [17 x i8] c"join_buffer_size\00"
@.str.12 = [16 x i8] c"max_connections\00"
@.str.13 = [5 x i8] c"%llu\00"
define void @f_maxmemory(i8* %0, i64 %1) {
%3 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strtoull(i32 %3, i32* null, i32 10)
%5 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 @strtoull(i32 %5, i32* null, i32 10)
%7 = icmp ugt i64 %4, %6
%8 = select i1 %7, i64 %6, i64 %4
%9 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i64 @strtoull(i32 %9, i32* null, i32 10)
%11 = add i64 %10, %8
%12 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i64 @strtoull(i32 %12, i32* null, i32 10)
%14 = add i64 %11, %13
%15 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i64 @strtoull(i32 %15, i32* null, i32 10)
%17 = add i64 %14, %16
%18 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%19 = tail call i64 @strtoull(i32 %18, i32* null, i32 10)
%20 = add i64 %17, %19
%21 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%22 = tail call i64 @strtoull(i32 %21, i32* null, i32 10)
%23 = add i64 %20, %22
%24 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%25 = tail call i64 @strtoull(i32 %24, i32* null, i32 10)
%26 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%27 = tail call i64 @strtoull(i32 %26, i32* null, i32 10)
%28 = add i64 %27, %25
%29 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%30 = tail call i64 @strtoull(i32 %29, i32* null, i32 10)
%31 = add i64 %28, %30
%32 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%33 = tail call i64 @strtoull(i32 %32, i32* null, i32 10)
%34 = add i64 %31, %33
%35 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%36 = tail call i64 @strtoull(i32 %35, i32* null, i32 10)
%37 = add i64 %34, %36
%38 = tail call i32 @get_var(i8* %0, i64 %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%39 = tail call i64 @strtoull(i32 %38, i32* null, i32 10)
%40 = mul i64 %39, %37
%41 = add i64 %23, %40
%42 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64 %41)
ret void
}