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

/* Variables and functions */
int abs(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ pid_ram(int const);
int /*<<< orphan*/ puts(char *);
int sprintf(char *, char *, ...);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcpy(char *, char *);
void dump_srv_topology(char *buf, FILE *fo, char *SERVER_NAME, int *process_pid,
                       int nbr_pids, int *pids) {
  sprintf(buf,
          "> Server '%s' process topology:\n"
          "---------------------------------------------\n",
          SERVER_NAME);
  fputs(buf, fo);
  fprintf(stdout, "%s", buf);
  float mem_sum = 0;
  int i = nbr_pids;
  while (i--) {
    const int pid = abs(pids[i]);
    char *p = buf + sprintf(buf, "%3d] pid:%d ", i, pid);
    if (pids[i] < 0) {
      float mem = (float)pid_ram(pid) / (1024. * 1024.);
      mem_sum += mem;
      sprintf(p, "Process RAM: %.02f MB\n", mem);
      *process_pid = pid;
    } else
      strcpy(p, "Thread\n");
    fputs(buf, fo);
    fprintf(stdout, "%s", buf);
  }
  sprintf(buf,
          "---------------------------------------------\n"
          "Total '%s' server footprint: %.02f MB",
          SERVER_NAME, mem_sum);
  puts(buf);
  fprintf(fo, "%s\n", buf);
}


x86 assembly (clang, -O0):
<dump_srv_topology>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fputs@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8f(%rip),%rsi
call   1080 <fprintf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x38(%rbp)
cmp    $0x0,%eax
je     12de <dump_srv_topology+0x16e>
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <abs@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    12a2 <dump_srv_topology+0x132>
mov    -0x3c(%rbp),%edi
call   1070 <pid_ram@plt>
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xda3(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x48(%rbp),%rdi
movss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdda(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b2 <dump_srv_topology+0x142>
mov    -0x48(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fputs@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd83(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11db <dump_srv_topology+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd90(%rip),%rsi
mov    $0x1,%al
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_srv_topology>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r15
mov    %r8d,%ebp
mov    %rcx,0x10(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
mov    %rdx,0x8(%rsp)
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rsi
mov    %rbx,%rdi
call   1050 <fputs@plt>
test   %ebp,%ebp
je     1284 <dump_srv_topology+0x124>
movslq %ebp,%rax
add    $0xffffffff,%ebp
lea    (%r15,%rax,4),%r13
add    $0xfffffffffffffffc,%r13
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
jmp    1209 <dump_srv_topology+0xa9>
mov    %r15,%rdi
lea    0xe9d(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%rsi
mov    %rbx,%rdi
call   1050 <fputs@plt>
add    $0xfffffffffffffffc,%r13
add    $0xffffffff,%ebp
jae    128d <dump_srv_topology+0x12d>
mov    0x0(%r13),%eax
mov    %eax,%r12d
neg    %r12d
cmovs  %eax,%r12d
mov    %rbx,%rdi
lea    0xe32(%rip),%rsi
mov    %ebp,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1080 <sprintf@plt>
movslq %eax,%r15
add    %rbx,%r15
cmpl   $0x0,0x0(%r13)
jns    11d0 <dump_srv_topology+0x70>
mov    %r12d,%edi
call   1060 <pid_ram@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mulss  0xdae(%rip),%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
lea    0xdf0(%rip),%rsi
mov    $0x1,%al
call   1080 <sprintf@plt>
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
jmp    11df <dump_srv_topology+0x7f>
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde1(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
mov    $0x1,%al
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>

LLVM IR (-O0):
@.str = [79 x i8] c"> Server '%s' process topology:\0A---------------------------------------------\0A\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [13 x i8] c"%3d] pid:%d \00"
@.str.3 = [23 x i8] c"Process RAM: %.02f MB\0A\00"
@.str.4 = [8 x i8] c"Thread\0A\00"
@.str.5 = [84 x i8] c"---------------------------------------------\0ATotal '%s' server footprint: %.02f MB\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define void @dump_srv_topology(i8* %0, i32* %1, i8* %2, i32* %3, i32 %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca float
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca float
store i8* %0, i8** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32* %5, i32** %12
%18 = load i8*, i8** %7
%19 = load i8*, i8** %9
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %7
%22 = load i32*, i32** %8
%23 = call i32 @fputs(i8* %21, i32* %22)
%24 = load i32*, i32** @stdout
%25 = load i8*, i8** %7
%26 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store float 0.000000e+00, float* %13
%27 = load i32, i32* %11
store i32 %27, i32* %14
br label %28
28: ; preds = %71, %6
%29 = load i32, i32* %14
%30 = add nsw i32 %29, -1
store i32 %30, i32* %14
%31 = icmp ne i32 %29, 0
br i1 %31, label %32, label %78
32: ; preds = %28
%33 = load i32*, i32** %12
%34 = load i32, i32* %14
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @abs(i32 %37)
store i32 %38, i32* %15
%39 = load i8*, i8** %7
%40 = load i8*, i8** %7
%41 = load i32, i32* %14
%42 = load i32, i32* %15
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %42)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %39, i64 %44
store i8* %45, i8** %16
%46 = load i32*, i32** %12
%47 = load i32, i32* %14
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = load i32, i32* %49
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %68
52: ; preds = %32
%53 = load i32, i32* %15
%54 = call i64 @pid_ram(i32 %53)
%55 = sitofp i64 %54 to float
%56 = fpext float %55 to double
%57 = fdiv double %56, 0x4130000000000000
%58 = fptrunc double %57 to float
store float %58, float* %17
%59 = load float, float* %17
%60 = load float, float* %13
%61 = fadd float %60, %59
store float %61, float* %13
%62 = load i8*, i8** %16
%63 = load float, float* %17
%64 = fpext float %63 to double
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %64)
%66 = load i32, i32* %15
%67 = load i32*, i32** %10
store i32 %66, i32* %67
br label %71
68: ; preds = %32
%69 = load i8*, i8** %16
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %68, %52
%72 = load i8*, i8** %7
%73 = load i32*, i32** %8
%74 = call i32 @fputs(i8* %72, i32* %73)
%75 = load i32*, i32** @stdout
%76 = load i8*, i8** %7
%77 = call i32 @fprintf(i32* %75, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %76)
br label %28
78: ; preds = %28
%79 = load i8*, i8** %7
%80 = load i8*, i8** %9
%81 = load float, float* %13
%82 = fpext float %81 to double
%83 = call i32 (i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0), i8* %80, double %82)
%84 = load i8*, i8** %7
%85 = call i32 @puts(i8* %84)
%86 = load i32*, i32** %8
%87 = load i8*, i8** %7
%88 = call i32 @fprintf(i32* %86, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %87)
ret void
}

LLVM IR (-O2):
@.str = [79 x i8] c"> Server '%s' process topology:\0A---------------------------------------------\0A\00"
@stdout = global i32* null
@.str.2 = [13 x i8] c"%3d] pid:%d \00"
@.str.3 = [23 x i8] c"Process RAM: %.02f MB\0A\00"
@.str.4 = [8 x i8] c"Thread\0A\00"
@.str.5 = [84 x i8] c"---------------------------------------------\0ATotal '%s' server footprint: %.02f MB\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define void @dump_srv_topology(i8* %0, i32* nocapture %1, i8* %2, i32* nocapture writeonly %3, i32 %4, i32* nocapture %5) {
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = tail call i32 @fputs(i8* %0, i32* %1)
%9 = load i32*, i32** @stdout
%10 = tail call i32 @fputs(i8* %0, i32* %9)
%11 = icmp eq i32 %4, 0
br i1 %11, label %42, label %12
12: ; preds = %6
%13 = sext i32 %4 to i64
br label %14
14: ; preds = %12, %36
%15 = phi i64 [ %13, %12 ], [ %17, %36 ]
%16 = phi float [ 0.000000e+00, %12 ], [ %37, %36 ]
%17 = add nsw i64 %15, -1
%18 = getelementptr inbounds i32, i32* %5, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 @llvm.abs.i32(i32 %19, i1 true)
%21 = trunc i64 %17 to i32
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %20)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i32, i32* %18
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %14
%28 = tail call i64 @pid_ram(i32 %20)
%29 = sitofp i64 %28 to float
%30 = fmul float %29, 0x3EB0000000000000
%31 = fadd float %16, %30
%32 = fpext float %30 to double
%33 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %32)
store i32 %20, i32* %3
br label %36
34: ; preds = %14
%35 = tail call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %27
%37 = phi float [ %31, %27 ], [ %16, %34 ]
%38 = tail call i32 @fputs(i8* %0, i32* %1)
%39 = load i32*, i32** @stdout
%40 = tail call i32 @fputs(i8* %0, i32* %39)
%41 = icmp eq i32 %21, 0
br i1 %41, label %42, label %14
42: ; preds = %36, %6
%43 = phi float [ 0.000000e+00, %6 ], [ %37, %36 ]
%44 = fpext float %43 to double
%45 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.5, i64 0, i64 0), i8* %2, double %44)
%46 = tail call i32 @puts(i8* dereferenceable(1) %0)
%47 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %0)
ret void
}