#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 atoi(char *);
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int toolame_read_stat(int *current) {
  char temp[1024];
  char string[100];
  char *string1;
  int bytes_read;
  bytes_read = read(0, (void *)temp, sizeof(temp));
  if (bytes_read > 16) {
    sscanf(&temp[1], "%s]", string);
    *current = atoi(string);
    return (0);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<toolame_read_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1030 <read@plt>
mov    %eax,-0x48c(%rbp)
cmpl   $0x10,-0x48c(%rbp)
jle    11a3 <toolame_read_stat+0x73>
lea    -0x410(%rbp),%rdi
add    $0x1,%rdi
lea    -0x480(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1040 <sscanf@plt>
lea    -0x480(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11aa <toolame_read_stat+0x7a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toolame_read_stat>:
push   %r14
push   %rbx
sub    $0x478,%rsp
mov    %rdi,%rbx
lea    0x70(%rsp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1030 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x11,%ecx
jl     117d <toolame_read_stat+0x4d>
lea    0x71(%rsp),%rdi
lea    0xe9a(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    %r14,%rdi
call   1050 <atoi@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x478,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s]\00"
define i32 @toolame_read_stat(i32* nocapture writeonly %0) {
%2 = alloca [1024 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %4, i32 1024)
%7 = icmp sgt i32 %6, 16
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%11 = call i32 @atoi(i8* %5)
store i32 %11, i32* %0
br label %12
12: ; preds = %1, %8
%13 = phi i32 [ 0, %8 ], [ -1, %1 ]
ret i32 %13
}