#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 */
unsigned int atoi(char *);
int read(int /*<<< orphan*/, void *, int);
scalar_t__ strchr(char *, char);
scalar_t__ strstr(char *, char *);
int flac_read_stat(unsigned int *current) {
  char temp[160];
  int bytes_read;
  char *p;
  char *q;
  bytes_read = read(0, (void *)temp, sizeof(temp));
  if (bytes_read) {
    if (p = (char *)strstr(temp, "wav: ")) {
      p += 5;
      if (q = (char *)strchr(p, '%')) {
        *q = '\0';
        *current = atoi(p);
        return (0);
      }
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<flac_read_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0xb0(%rbp),%rsi
xor    %edi,%edi
mov    $0xa0,%edx
call   1040 <read@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
je     1201 <flac_read_stat+0xc1>
lea    -0xb0(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0xc0(%rbp)
cmp    $0x0,%rax
je     11fc <flac_read_stat+0xbc>
mov    -0xc0(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
je     11f7 <flac_read_stat+0xb7>
mov    -0xc8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xc0(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1208 <flac_read_stat+0xc8>
jmp    11fc <flac_read_stat+0xbc>
jmp    1201 <flac_read_stat+0xc1>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flac_read_stat>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rdi,%r14
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0xa0,%edx
call   1040 <read@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     11a3 <flac_read_stat+0x63>
lea    0xe93(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     11a3 <flac_read_stat+0x63>
mov    %rax,%rbx
add    $0x5,%rbx
mov    %rbx,%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a3 <flac_read_stat+0x63>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"wav: \00"
define i32 @flac_read_stat(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [160 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %3
%8 = getelementptr inbounds [160 x i8], [160 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 0, i8* %8, i32 160)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %1
%13 = getelementptr inbounds [160 x i8], [160 x i8]* %4, i64 0, i64 0
%14 = call i64 @strstr(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 5
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i64 @strchr(i8* %20, i8 signext 37)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i8*, i8** %7
store i8 0, i8* %25
%26 = load i8*, i8** %6
%27 = call i32 @atoi(i8* %26)
%28 = load i32*, i32** %3
store i32 %27, i32* %28
store i32 0, i32* %2
br label %32
29: ; preds = %17
br label %30
30: ; preds = %29, %12
br label %31
31: ; preds = %30, %1
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %24
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"wav: \00"
define i32 @flac_read_stat(i32* nocapture writeonly %0) {
%2 = alloca [160 x i8]
%3 = getelementptr inbounds [160 x i8], [160 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 0, i8* %3, i32 160)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = inttoptr i64 %7 to i8*
%11 = getelementptr inbounds i8, i8* %10, i64 5
%12 = call i64 @strchr(i8* %11, i8 signext 37)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = inttoptr i64 %12 to i8*
store i8 0, i8* %15
%16 = call i32 @atoi(i8* %11)
store i32 %16, i32* %0
br label %17
17: ; preds = %1, %9, %6, %14
%18 = phi i32 [ 0, %14 ], [ -1, %6 ], [ -1, %9 ], [ -1, %1 ]
ret i32 %18
}