#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 */
double atof(char *);
int /*<<< orphan*/ bss_log(char *, char *, int);
int i0(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
double calc_wgt(int np) {
  int return_code;
  int r = 0;
  int bigr = 0;
  int rload = 4;
  int bigrload = 5;
  int weight_function = 2;
  double weight;
  char bss_command[1024];
  char bss_result[1024];
  sprintf(bss_command, "w fn=%d r=%d bigr=%d rload=%d bigrload=%d n=%d",
          weight_function, r, bigr, rload, bigrload, np);
  if ((return_code = i0(bss_command, bss_result)) < 0) {
    bss_log("calc_wgt()", bss_command, return_code);
    return -1.0f;
  }
  weight = atof(bss_result);
  return weight;
}


x86 assembly (clang, -O0):
<calc_wgt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
movl   $0x5,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%r10d
mov    -0xc(%rbp),%eax
lea    0xe74(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <sprintf@plt>
lea    -0x430(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1060 <i0@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11e8 <calc_wgt+0xa8>
lea    -0x430(%rbp),%rsi
mov    -0x10(%rbp),%edx
lea    0xe66(%rip),%rdi
call   1040 <bss_log@plt>
movsd  0xe22(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1203 <calc_wgt+0xc3>
lea    -0x830(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_wgt>:
push   %rbx
sub    $0x800,%rsp
mov    %edi,%eax
lea    0xeb7(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x4,%r9d
push   %rax
push   $0x5
call   1050 <sprintf@plt>
add    $0x10,%rsp
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <i0@plt>
test   %eax,%eax
js     1191 <calc_wgt+0x51>
mov    %rsp,%rdi
call   1030 <atof@plt>
jmp    11af <calc_wgt+0x6f>
lea    0xe9f(%rip),%rdi
lea    0x400(%rsp),%rsi
mov    %eax,%edx
call   1040 <bss_log@plt>
movsd  0xe51(%rip),%xmm0
add    $0x800,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [47 x i8] c"w fn=%d r=%d bigr=%d rload=%d bigrload=%d n=%d\00"
@.str.1 = [11 x i8] c"calc_wgt()\00"
define double @calc_wgt(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
store i32 %0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 4, i32* %7
store i32 5, i32* %8
store i32 2, i32* %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%14 = load i32, i32* %9
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = load i32, i32* %3
%20 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16, i32 %17, i32 %18, i32 %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%23 = call i32 @i0(i8* %21, i8* %22)
store i32 %23, i32* %4
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %1
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%27 = load i32, i32* %4
%28 = call i32 @bss_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
store double -1.000000e+00, double* %2
br label %33
29: ; preds = %1
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%31 = call double @atof(i8* %30)
store double %31, double* %10
%32 = load double, double* %10
store double %32, double* %2
br label %33
33: ; preds = %29, %25
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@.str = [47 x i8] c"w fn=%d r=%d bigr=%d rload=%d bigrload=%d n=%d\00"
@.str.1 = [11 x i8] c"calc_wgt()\00"
define double @calc_wgt(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 2, i32 0, i32 0, i32 4, i32 5, i32 %0)
%7 = call i32 @i0(i8* %4, i8* %5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @bss_log(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %7)
br label %13
11: ; preds = %1
%12 = call double @atof(i8* %5)
br label %13
13: ; preds = %11, %9
%14 = phi double [ -1.000000e+00, %9 ], [ %12, %11 ]
ret double %14
}