#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 */
float get_cpu_usage();
char *get_msg(float);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, float);
int strlen(char *);
int add_cpuload_msg(char *buf, int buflen) {
  float usage = 0;
  const char *msg;
  int len = strlen(buf);
  if ((usage = get_cpu_usage()) < 0)
    msg = "....";
  else if (usage == 1000) {
    msg = "init";
    usage = 0;
  } else
    msg = get_msg(usage);
  snprintf(buf + len, buflen - len, "%s (%%CPU:%.1f)", msg, usage);
  return 0;
}


x86 assembly (clang, -O0):
<add_cpuload_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <get_cpu_usage@plt>
movaps %xmm0,%xmm1
movss  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    118e <add_cpuload_msg+0x4e>
lea    0xe7f(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11d5 <add_cpuload_msg+0x95>
movss  -0x10(%rbp),%xmm0
movss  0xe65(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    11c2 <add_cpuload_msg+0x82>
jp     11c2 <add_cpuload_msg+0x82>
lea    0xe58(%rip),%rax
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11d0 <add_cpuload_msg+0x90>
movss  -0x10(%rbp),%xmm0
call   1050 <get_msg@plt>
mov    %rax,-0x18(%rbp)
jmp    11d5 <add_cpuload_msg+0x95>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
movss  -0x10(%rbp),%xmm0
lea    0xe18(%rip),%rdx
call   1040 <snprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_cpuload_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1060 <get_cpu_usage@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    116d <add_cpuload_msg+0x2d>
lea    0xe99(%rip),%rcx
jmp    1198 <add_cpuload_msg+0x58>
ucomiss 0xe8c(%rip),%xmm0
jne    1184 <add_cpuload_msg+0x44>
jp     1184 <add_cpuload_msg+0x44>
lea    0xe8a(%rip),%rcx
xorps  %xmm0,%xmm0
jmp    1198 <add_cpuload_msg+0x58>
movss  %xmm0,0xc(%rsp)
call   1050 <get_msg@plt>
movss  0xc(%rsp),%xmm0
mov    %rax,%rcx
movslq %r14d,%rax
add    %rax,%rbx
sub    %eax,%ebp
lea    0xe67(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <snprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"....\00"
@.str.1 = [5 x i8] c"init\00"
@.str.2 = [16 x i8] c"%s (%%CPU:%.1f)\00"
define i32 @add_cpuload_msg(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca float
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = call float (...) @get_cpu_usage()
store float %10, float* %5
%11 = fcmp olt float %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
br label %21
13: ; preds = %2
%14 = load float, float* %5
%15 = fcmp oeq float %14, 1.000000e+03
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %6
store float 0.000000e+00, float* %5
br label %20
17: ; preds = %13
%18 = load float, float* %5
%19 = call i8* @get_msg(float %18)
store i8* %19, i8** %6
br label %20
20: ; preds = %17, %16
br label %21
21: ; preds = %20, %12
%22 = load i8*, i8** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %4
%27 = load i32, i32* %7
%28 = sub nsw i32 %26, %27
%29 = load i8*, i8** %6
%30 = load float, float* %5
%31 = call i32 @snprintf(i8* %25, i32 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %29, float %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"....\00"
@.str.1 = [5 x i8] c"init\00"
@.str.2 = [16 x i8] c"%s (%%CPU:%.1f)\00"
define i32 @add_cpuload_msg(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call float (...) @get_cpu_usage()
%5 = fcmp olt float %4, 0.000000e+00
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = fcmp oeq float %4, 1.000000e+03
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i8* @get_msg(float %4)
br label %10
10: ; preds = %6, %2, %8
%11 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %6 ]
%12 = phi float [ %4, %8 ], [ %4, %2 ], [ 0.000000e+00, %6 ]
%13 = sext i32 %3 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = sub nsw i32 %1, %3
%16 = tail call i32 @snprintf(i8* %14, i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %11, float %12)
ret i32 0
}