#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*/ error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mb_error_to_string(int);
int mb_query();
int mb_query_server();
int mb_query_total();
double pages_to_megabytes(int);
int /*<<< orphan*/ printf(char *, int, double);
void do_query(void) {
  int total;
  int server;
  int client;
  total = mb_query_total();
  if (total < 0) {
    error("mb_query_total() said %s\n", mb_error_to_string(total));
    ;
  }
  server = mb_query_server();
  if (server < 0) {
    error("mb_query_server() said %s\n", mb_error_to_string(server));
  }
  client = mb_query();
  if (client < 0) {
    error("mb_query() said %s\n", mb_error_to_string(client));
  }
  printf("total   %9d p (%.1f M)\n", total, pages_to_megabytes(total));
  printf("server  %9d p (%.1f M)\n", server, pages_to_megabytes(server));
  printf("client  %9d p (%.1f M)\n", client, pages_to_megabytes(client));
}


x86 assembly (clang, -O0):
<do_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <mb_query_total@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a2 <do_query+0x32>
mov    -0x4(%rbp),%edi
call   1090 <mb_error_to_string@plt>
mov    %eax,%esi
lea    0xe63(%rip),%rdi
call   1070 <error@plt>
mov    $0x0,%al
call   1060 <mb_query_server@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11cc <do_query+0x5c>
mov    -0x8(%rbp),%edi
call   1090 <mb_error_to_string@plt>
mov    %eax,%esi
lea    0xe53(%rip),%rdi
call   1070 <error@plt>
mov    $0x0,%al
call   1080 <mb_query@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11f6 <do_query+0x86>
mov    -0xc(%rbp),%edi
call   1090 <mb_error_to_string@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
call   1070 <error@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <pages_to_megabytes@plt>
mov    -0x18(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <pages_to_megabytes@plt>
mov    -0x14(%rbp),%esi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <pages_to_megabytes@plt>
mov    -0x10(%rbp),%esi
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_query>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <mb_query_total@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1198 <do_query+0x28>
mov    %r14d,%edi
call   1090 <mb_error_to_string@plt>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
call   1070 <error@plt>
xor    %eax,%eax
call   1060 <mb_query_server@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ba <do_query+0x4a>
mov    %ebp,%edi
call   1090 <mb_error_to_string@plt>
lea    0xe67(%rip),%rdi
mov    %eax,%esi
call   1070 <error@plt>
xor    %eax,%eax
call   1080 <mb_query@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11dc <do_query+0x6c>
mov    %ebx,%edi
call   1090 <mb_error_to_string@plt>
lea    0xe60(%rip),%rdi
mov    %eax,%esi
call   1070 <error@plt>
mov    %r14d,%edi
call   1050 <pages_to_megabytes@plt>
lea    0xe5e(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <pages_to_megabytes@plt>
lea    0xe60(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <pages_to_megabytes@plt>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"mb_query_total() said %s\0A\00"
@.str.1 = [27 x i8] c"mb_query_server() said %s\0A\00"
@.str.2 = [20 x i8] c"mb_query() said %s\0A\00"
@.str.3 = [24 x i8] c"total %9d p (%.1f M)\0A\00"
@.str.4 = [24 x i8] c"server %9d p (%.1f M)\0A\00"
@.str.5 = [24 x i8] c"client %9d p (%.1f M)\0A\00"
define void @do_query() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @mb_query_total()
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i32 @mb_error_to_string(i32 %8)
%10 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %0
%12 = call i32 (...) @mb_query_server()
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* %2
%17 = call i32 @mb_error_to_string(i32 %16)
%18 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %11
%20 = call i32 (...) @mb_query()
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %3
%25 = call i32 @mb_error_to_string(i32 %24)
%26 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %1
%29 = load i32, i32* %1
%30 = call double @pages_to_megabytes(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %28, double %30)
%32 = load i32, i32* %2
%33 = load i32, i32* %2
%34 = call double @pages_to_megabytes(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %32, double %34)
%36 = load i32, i32* %3
%37 = load i32, i32* %3
%38 = call double @pages_to_megabytes(i32 %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %36, double %38)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"mb_query_total() said %s\0A\00"
@.str.1 = [27 x i8] c"mb_query_server() said %s\0A\00"
@.str.2 = [20 x i8] c"mb_query() said %s\0A\00"
@.str.3 = [24 x i8] c"total %9d p (%.1f M)\0A\00"
@.str.4 = [24 x i8] c"server %9d p (%.1f M)\0A\00"
@.str.5 = [24 x i8] c"client %9d p (%.1f M)\0A\00"
define void @do_query() {
%1 = tail call i32 (...) @mb_query_total()
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @mb_error_to_string(i32 %1)
%5 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %3, %0
%7 = tail call i32 (...) @mb_query_server()
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @mb_error_to_string(i32 %7)
%11 = tail call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %6
%13 = tail call i32 (...) @mb_query()
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @mb_error_to_string(i32 %13)
%17 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %12
%19 = tail call double @pages_to_megabytes(i32 %1)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %1, double %19)
%21 = tail call double @pages_to_megabytes(i32 %7)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %7, double %21)
%23 = tail call double @pages_to_megabytes(i32 %13)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %13, double %23)
ret void
}