#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *val2str(char *str, float val, char *trailer_str) {
  if (((int32_t)(val) >= 1000000 && (int32_t)(val) <= 1000002)) {
    sprintf(str, "%-6s %s",
            ((int32_t)(val) == 1000000   ? "FAULTY"
             : (int32_t)(val) == 1000001 ? "OVPRES"
             : (int32_t)(val) == 1000002 ? "NOVAL"
                                         : "????"),
            trailer_str);
  } else if (val < 1000.0) {
    sprintf(str, "%-6.2f %s", val, trailer_str);
  } else {
    sprintf(str, "%-6.0f %s", val, trailer_str);
  }
  return str;
}


x86 assembly (clang, -O0):
<val2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cvttss2si -0xc(%rbp),%eax
cmp    $0xf4240,%eax
jl     11d5 <val2str+0xc5>
cvttss2si -0xc(%rbp),%eax
cmp    $0xf4242,%eax
jg     11d5 <val2str+0xc5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cvttss2si -0xc(%rbp),%eax
cmp    $0xf4240,%eax
jne    116d <val2str+0x5d>
lea    0xeac(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b6 <val2str+0xa6>
cvttss2si -0xc(%rbp),%eax
cmp    $0xf4241,%eax
jne    118d <val2str+0x7d>
lea    0xe93(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11ae <val2str+0x9e>
cvttss2si -0xc(%rbp),%edx
lea    0xe8b(%rip),%rax
lea    0xe7e(%rip),%rcx
cmp    $0xf4242,%edx
cmove  %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1238 <val2str+0x128>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe1a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1214 <val2str+0x104>
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rdx
lea    0xe21(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1233 <val2str+0x123>
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rdx
lea    0xe07(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1238 <val2str+0x128>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<val2str>:
push   %rbx
mov    %rsi,%rcx
mov    %rdi,%rbx
cvttss2si %xmm0,%eax
lea    -0xf4240(%rax),%edx
cmp    $0x2,%edx
ja     1160 <val2str+0x50>
cmp    $0xf4241,%eax
lea    0xee1(%rip),%rdx
lea    0xee1(%rip),%rsi
cmove  %rdx,%rsi
cmp    $0xf4240,%eax
lea    0xec3(%rip),%rdx
cmovne %rsi,%rdx
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    1191 <val2str+0x81>
movaps %xmm0,%xmm1
cvtss2sd %xmm0,%xmm0
movss  0xe91(%rip),%xmm2
ucomiss %xmm1,%xmm2
jbe    117d <val2str+0x6d>
lea    0xea5(%rip),%rsi
jmp    1184 <val2str+0x74>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    %rcx,%rdx
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%-6s %s\00"
@.str.1 = [7 x i8] c"FAULTY\00"
@.str.2 = [7 x i8] c"OVPRES\00"
@.str.3 = [6 x i8] c"NOVAL\00"
@.str.4 = [5 x i8] c"????\00"
@.str.5 = [10 x i8] c"%-6.2f %s\00"
@.str.6 = [10 x i8] c"%-6.0f %s\00"
define i8* @val2str(i8* %0, float %1, i8* %2) {
%4 = alloca i8*
%5 = alloca float
%6 = alloca i8*
store i8* %0, i8** %4
store float %1, float* %5
store i8* %2, i8** %6
%7 = load float, float* %5
%8 = fptosi float %7 to i32
%9 = icmp sge i32 %8, 1000000
br i1 %9, label %10, label %37
10: ; preds = %3
%11 = load float, float* %5
%12 = fptosi float %11 to i32
%13 = icmp sle i32 %12, 1000002
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load float, float* %5
%17 = fptosi float %16 to i32
%18 = icmp eq i32 %17, 1000000
br i1 %18, label %19, label %20
19: ; preds = %14
br label %33
20: ; preds = %14
%21 = load float, float* %5
%22 = fptosi float %21 to i32
%23 = icmp eq i32 %22, 1000001
br i1 %23, label %24, label %25
24: ; preds = %20
br label %31
25: ; preds = %20
%26 = load float, float* %5
%27 = fptosi float %26 to i32
%28 = icmp eq i32 %27, 1000002
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
br label %31
31: ; preds = %25, %24
%32 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %24 ], [ %30, %25 ]
br label %33
33: ; preds = %31, %19
%34 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %19 ], [ %32, %31 ]
%35 = load i8*, i8** %6
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35)
br label %54
37: ; preds = %10, %3
%38 = load float, float* %5
%39 = fpext float %38 to double
%40 = fcmp olt double %39, 1.000000e+03
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = load float, float* %5
%44 = fpext float %43 to double
%45 = load i8*, i8** %6
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %44, i8* %45)
br label %53
47: ; preds = %37
%48 = load i8*, i8** %4
%49 = load float, float* %5
%50 = fpext float %49 to double
%51 = load i8*, i8** %6
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %50, i8* %51)
br label %53
53: ; preds = %47, %41
br label %54
54: ; preds = %53, %33
%55 = load i8*, i8** %4
ret i8* %55
}

LLVM IR (-O2):
@.str = [8 x i8] c"%-6s %s\00"
@.str.1 = [7 x i8] c"FAULTY\00"
@.str.2 = [7 x i8] c"OVPRES\00"
@.str.3 = [6 x i8] c"NOVAL\00"
@.str.5 = [10 x i8] c"%-6.2f %s\00"
@.str.6 = [10 x i8] c"%-6.0f %s\00"
define i8* @val2str(i8* returned writeonly %0, float %1, i8* %2) {
%4 = fptosi float %1 to i32
%5 = add i32 %4, -1000000
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = icmp eq i32 %4, 1000001
%9 = select i1 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%10 = icmp eq i32 %4, 1000000
%11 = select i1 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %9
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %2)
br label %20
13: ; preds = %3
%14 = fpext float %1 to double
%15 = fcmp olt float %1, 1.000000e+03
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %14, i8* %2)
br label %20
18: ; preds = %13
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %14, i8* %2)
br label %20
20: ; preds = %16, %18, %7
ret i8* %0
}