#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int /*<<< orphan*/ stderr;
double extract_power_from_mw100_response(char response[]) {
  int i;
  double power;
  for (i = 0; response[i] != 0; i++) {
    if (response[i] == 'N') {
      sscanf(&response[i], "N %*d W + %lf", &power);
      return power;
    }
  }
  fprintf(stderr, "[-] Response: \n%s\n", response);
  fprintf(stderr, "[-] Unable to extract power from response. \n");
  return -1;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119a <extract_power_from_mw100_response+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4e,%eax
jne    1187 <extract_power_from_mw100_response+0x67>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xe99(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <extract_power_from_mw100_response+0xb9>
jmp    118c <extract_power_from_mw100_response+0x6c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <extract_power_from_mw100_response+0x13>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsd  0xe2c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
je     1143 <extract_power_from_mw100_response+0x23>
cmp    $0x4e,%dl
je     1177 <extract_power_from_mw100_response+0x57>
add    $0x1,%rcx
jmp    1130 <extract_power_from_mw100_response+0x10>
mov    0x2e96(%rip),%rbx
mov    (%rbx),%edi
lea    0xec3(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xec3(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movsd  0xe8b(%rip),%xmm0
jmp    1196 <extract_power_from_mw100_response+0x76>
mov    %ecx,%ecx
add    %rcx,%rax
lea    0xe85(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"N %*d W + %lf\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"[-] Response: \0A%s\0A\00"
@.str.2 = [45 x i8] c"[-] Unable to extract power from response. \0A\00"
define double @extract_power_from_mw100_response(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %30, %1
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 78
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double* %5)
%28 = load double, double* %5
store double %28, double* %2
br label %39
29: ; preds = %14
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %6
33: ; preds = %6
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %3
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store double -1.000000e+00, double* %2
br label %39
39: ; preds = %33, %22
%40 = load double, double* %2
ret double %40
}

LLVM IR (-O2):
@.str = [14 x i8] c"N %*d W + %lf\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"[-] Response: \0A%s\0A\00"
@.str.2 = [45 x i8] c"[-] Unable to extract power from response. \0A\00"
define double @extract_power_from_mw100_response(i8* %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
br label %4
4: ; preds = %13, %1
%5 = phi i64 [ %14, %13 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %13 [
i8 0, label %15
i8 78, label %8
]
8: ; preds = %4
%9 = and i64 %5, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double* %2)
%12 = load double, double* %2
br label %20
13: ; preds = %4
%14 = add nuw i64 %5, 1
br label %4
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %15, %8
%21 = phi double [ %12, %8 ], [ -1.000000e+00, %15 ]
ret double %21
}