#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 */
double atof(char *);
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int xingenc_read_stat(double *current) {
  char temp[4096];
  char string[4096];
  int bytes_read;
  bytes_read = read(0, (void *)temp, sizeof(temp));
  if (bytes_read) {
    sscanf(temp, " %s%% [", string);
    *current = atof(string) / 100.0;
    return (0);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<xingenc_read_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1010(%rbp),%rsi
xor    %edi,%edi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
je     11ab <xingenc_read_stat+0x7b>
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rdx
lea    0xe8e(%rip),%rsi
call   1050 <sscanf@plt>
lea    -0x2010(%rbp),%rdi
call   1030 <atof@plt>
movsd  0xe6d(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11b2 <xingenc_read_stat+0x82>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xingenc_read_stat>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %eax,%eax
je     1185 <xingenc_read_stat+0x55>
lea    0xead(%rip),%rsi
mov    %rsp,%rdi
lea    0x1000(%rsp),%r15
mov    %r15,%rdx
call   1050 <sscanf@plt>
mov    %r15,%rdi
call   1030 <atof@plt>
divsd  0xe82(%rip),%xmm0
movsd  %xmm0,(%r14)
jmp    118a <xingenc_read_stat+0x5a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c" %s%% [\00"
define i32 @xingenc_read_stat(double* %0) {
%2 = alloca i32
%3 = alloca double*
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca i32
store double* %0, double** %3
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 0, i8* %7, i32 4096)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %1
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%14 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = call double @atof(i8* %15)
%17 = fdiv double %16, 1.000000e+02
%18 = load double*, double** %3
store double %17, double* %18
store i32 0, i32* %2
br label %20
19: ; preds = %1
store i32 -1, i32* %2
br label %20
20: ; preds = %19, %11
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [8 x i8] c" %s%% [\00"
define i32 @xingenc_read_stat(double* nocapture writeonly %0) {
%2 = alloca [4096 x i8]
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %4, i32 4096)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call double @atof(i8* %5)
%11 = fdiv double %10, 1.000000e+02
store double %11, double* %0
br label %12
12: ; preds = %1, %8
%13 = phi i32 [ 0, %8 ], [ -1, %1 ]
ret i32 %13
}