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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int read_acqufile_bin(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *scanbinfile(FILE *file, char *pattern1) {
  static char resultbuf[250 + 1];
  char *p, pattern[250 + 1], buf[250 + 1];
  int len, ok;
  long pos = ftell(file);
  rewind(file);
  strncpy(pattern, pattern1, 250);
  pattern[250] = '\0';
  len = strlen(pattern);
  if (len >= 2) {
    p = pattern + len - 2;
    if (p[0] == '%' && p[1] == 's')
      *p = '\0';
  }
  resultbuf[0] = '\0';
  ok = read_acqufile_bin(file, resultbuf, pattern);
  fseek(file, pos, SEEK_SET);
  if (ok)
    return resultbuf;
  return NULL;
}


x86 assembly (clang, -O0):
<scanbinfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x230(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xfa,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x26(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x2,-0x224(%rbp)
jl     120a <scanbinfile+0xaa>
lea    -0x120(%rbp),%rax
movslq -0x224(%rbp),%rcx
add    %rcx,%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1205 <scanbinfile+0xa5>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x73,%eax
jne    1205 <scanbinfile+0xa5>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    120a <scanbinfile+0xaa>
movb   $0x0,0x2e4f(%rip)
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0x2e3d(%rip),%rsi
call   1080 <read_acqufile_bin@plt>
mov    %eax,-0x228(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x230(%rbp),%rsi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmpl   $0x0,-0x228(%rbp)
je     1264 <scanbinfile+0x104>
lea    0x2e05(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    126c <scanbinfile+0x10c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanbinfile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <ftell@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0xfa,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xfa(%rsp)
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11c2 <scanbinfile+0x62>
mov    %eax,%eax
cmpb   $0x25,-0x2(%rsp,%rax,1)
jne    11c2 <scanbinfile+0x62>
cmpb   $0x73,-0x1(%rsp,%rax,1)
jne    11c2 <scanbinfile+0x62>
movb   $0x0,-0x2(%rsp,%rax,1)
movb   $0x0,0x2e97(%rip)
lea    0x2e90(%rip),%r15
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <read_acqufile_bin@plt>
mov    %eax,%ebp
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fseek@plt>
xor    %eax,%eax
test   %ebp,%ebp
cmovne %r15,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@scanbinfile.resultbuf = internal global [251 x i8] zeroinitializer
@SEEK_SET = global i32 0
define i8* @scanbinfile(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [251 x i8]
%8 = alloca [251 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
%12 = load i32*, i32** %4
%13 = call i64 @ftell(i32* %12)
store i64 %13, i64* %11
%14 = load i32*, i32** %4
%15 = call i32 @rewind(i32* %14)
%16 = getelementptr inbounds [251 x i8], [251 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 250)
%19 = getelementptr inbounds [251 x i8], [251 x i8]* %7, i64 0, i64 250
store i8 0, i8* %19
%20 = getelementptr inbounds [251 x i8], [251 x i8]* %7, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp sge i32 %22, 2
br i1 %23, label %24, label %44
24: ; preds = %2
%25 = getelementptr inbounds [251 x i8], [251 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 -2
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 37
br i1 %34, label %35, label %43
35: ; preds = %24
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 115
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = load i8*, i8** %6
store i8 0, i8* %42
br label %43
43: ; preds = %41, %35, %24
br label %44
44: ; preds = %43, %2
store i8 0, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0)
%45 = load i32*, i32** %4
%46 = getelementptr inbounds [251 x i8], [251 x i8]* %7, i64 0, i64 0
%47 = call i32 @read_acqufile_bin(i32* %45, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0), i8* %46)
store i32 %47, i32* %10
%48 = load i32*, i32** %4
%49 = load i64, i64* %11
%50 = load i32, i32* @SEEK_SET
%51 = call i32 @fseek(i32* %48, i64 %49, i32 %50)
%52 = load i32, i32* %10
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %44
store i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0), i8** %3
br label %56
55: ; preds = %44
store i8* null, i8** %3
br label %56
56: ; preds = %55, %54
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
@scanbinfile.resultbuf = internal global [251 x i8] zeroinitializer
@SEEK_SET = global i32 0
define i8* @scanbinfile(i32* %0, i8* %1) {
%3 = alloca [251 x i8]
%4 = getelementptr inbounds [251 x i8], [251 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @ftell(i32* %0)
%6 = tail call i32 @rewind(i32* %0)
%7 = call i32 @strncpy(i8* %4, i8* %1, i32 250)
%8 = getelementptr inbounds [251 x i8], [251 x i8]* %3, i64 0, i64 250
store i8 0, i8* %8
%9 = call i32 @strlen(i8* %4)
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds [251 x i8], [251 x i8]* %3, i64 0, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 37
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %13, i64 -1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 115
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 0, i8* %14
br label %22
22: ; preds = %11, %17, %21, %2
store i8 0, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0)
%23 = call i32 @read_acqufile_bin(i32* %0, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0), i8* %4)
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %0, i64 %5, i32 %24)
%26 = icmp eq i32 %23, 0
%27 = select i1 %26, i8* null, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @scanbinfile.resultbuf, i64 0, i64 0)
ret i8* %27
}