#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 *, unsigned int *, unsigned int *);
int read_stat(unsigned int *current, unsigned int *length) {
  char temp[1024];
  int bytes_read;
  bytes_read = read(0, (void *)temp, sizeof(temp));
  if (bytes_read) {
    sscanf(temp, "%u / %u", current, length);
    return (0);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<read_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1030 <read@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     1180 <read_stat+0x60>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe91(%rip),%rsi
call   1040 <sscanf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1187 <read_stat+0x67>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stat>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1030 <read@plt>
test   %eax,%eax
je     115e <read_stat+0x3e>
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <sscanf@plt>
jmp    1163 <read_stat+0x43>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%u / %u\00"
define i32 @read_stat(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, 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 ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = load i32*, i32** %5
%16 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %14, i32* %15)
store i32 0, i32* %3
br label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [8 x i8] c"%u / %u\00"
define i32 @read_stat(i32* %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 1024)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %0, i32* %1)
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ 0, %7 ], [ -1, %2 ]
ret i32 %10
}