#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*/ temp;

/* Variables and functions */
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ sscanf(char *, char *, float *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int mppenc_read_stat(float *current) {
  char temp[2048];
  char string[2048];
  int bytes_read;
  int bytes_left;
  char *kbps = "kbps";
  char *string_ptr;
  char *temp_ptr;
  temp_ptr = temp;
  bytes_read = read(0, (void *)temp, sizeof(temp));
  if (bytes_read) {
    temp[bytes_read] = '\0';
    string_ptr = strstr(temp_ptr, kbps);
    bytes_left = string_ptr - temp_ptr;
    if ((bytes_left < 20) && (bytes_left > 8)) {
      if (temp[0] == '\015') {
        temp_ptr = temp;
        temp_ptr++;
        strcpy(string, temp_ptr);
      } else {
        strcpy(string, temp);
      }
      sscanf(string, "%f", current);
      if (!(*current > 100 || *current <= 0))
        return (0);
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<mppenc_read_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x1020(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x810(%rbp),%rsi
xor    %edi,%edi
mov    $0x800,%edx
call   1040 <read@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x0,-0x1014(%rbp)
je     129c <mppenc_read_stat+0x15c>
movslq -0x1014(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
mov    -0x1030(%rbp),%rdi
mov    -0x1020(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
mov    -0x1030(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1018(%rbp)
cmpl   $0x14,-0x1018(%rbp)
jge    1297 <mppenc_read_stat+0x157>
cmpl   $0x8,-0x1018(%rbp)
jle    1297 <mppenc_read_stat+0x157>
movsbl -0x810(%rbp),%eax
cmp    $0xd,%eax
jne    1233 <mppenc_read_stat+0xf3>
lea    -0x810(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1246 <mppenc_read_stat+0x106>
lea    -0x1010(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movss  0xd93(%rip),%xmm1
ucomiss %xmm1,%xmm0
ja     1292 <mppenc_read_stat+0x152>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
ucomiss (%rax),%xmm0
jae    1292 <mppenc_read_stat+0x152>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <mppenc_read_stat+0x163>
jmp    1297 <mppenc_read_stat+0x157>
jmp    129c <mppenc_read_stat+0x15c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mppenc_read_stat>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x800,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ce <mppenc_read_stat+0x8e>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe95(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strstr@plt>
sub    %ebx,%eax
add    $0xfffffff7,%eax
cmp    $0xa,%eax
ja     11ce <mppenc_read_stat+0x8e>
cmpb   $0xd,(%rsp)
lea    0x1(%rsp),%rax
cmove  %rax,%rbx
lea    0x800(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe5e(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
movss  (%r14),%xmm0
ucomiss 0xe3e(%rip),%xmm0
ja     11ce <mppenc_read_stat+0x8e>
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jb     11d3 <mppenc_read_stat+0x93>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"kbps\00"
@.str.1 = [3 x i8] c"%f\00"
define i32 @mppenc_read_stat(float* %0) {
%2 = alloca i32
%3 = alloca float*
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store float* %0, float** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
store i8* %11, i8** %10
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 0, i8* %12, i32 2048)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %64
16: ; preds = %1
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %10
%21 = load i8*, i8** %8
%22 = call i8* @strstr(i8* %20, i8* %21)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = load i8*, i8** %10
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 20
br i1 %30, label %31, label %63
31: ; preds = %16
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 8
br i1 %33, label %34, label %63
34: ; preds = %31
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 13
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %10
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%44 = load i8*, i8** %10
%45 = call i32 @strcpy(i8* %43, i8* %44)
br label %50
46: ; preds = %34
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%49 = call i32 @strcpy(i8* %47, i8* %48)
br label %50
50: ; preds = %46, %39
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%52 = load float*, float** %3
%53 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %52)
%54 = load float*, float** %3
%55 = load float, float* %54
%56 = fcmp ogt float %55, 1.000000e+02
br i1 %56, label %62, label %57
57: ; preds = %50
%58 = load float*, float** %3
%59 = load float, float* %58
%60 = fcmp ole float %59, 0.000000e+00
br i1 %60, label %62, label %61
61: ; preds = %57
store i32 0, i32* %2
br label %65
62: ; preds = %57, %50
br label %63
63: ; preds = %62, %31, %16
br label %64
64: ; preds = %63, %1
store i32 -1, i32* %2
br label %65
65: ; preds = %64, %61
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [5 x i8] c"kbps\00"
@.str.1 = [3 x i8] c"%f\00"
define i32 @mppenc_read_stat(float* %0) {
%2 = alloca [2048 x i8]
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %4, i32 2048)
%7 = icmp eq i32 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %1
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint [2048 x i8]* %2 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = add i32 %15, -9
%17 = icmp ult i32 %16, 11
br i1 %17, label %18, label %29
18: ; preds = %8
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 13
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 1
%22 = select i1 %20, i8* %21, i8* %4
%23 = call i32 @strcpy(i8* %5, i8* %22)
%24 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %0)
%25 = load float, float* %0
%26 = fcmp ule float %25, 1.000000e+02
%27 = fcmp ugt float %25, 0.000000e+00
%28 = and i1 %26, %27
br i1 %28, label %30, label %29
29: ; preds = %8, %18, %1
br label %30
30: ; preds = %18, %29
%31 = phi i32 [ -1, %29 ], [ 0, %18 ]
ret i32 %31
}