#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 */
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long const, int);
long ftell(int /*<<< orphan*/ *);
int find_next_in_filestream(FILE *file_stream, char some_char) {
  const long int origin = ftell(file_stream);
  int current_position = 0;
  char file_buffer[1];
  while (fread(file_buffer, 1, 1, file_stream) != 0 &&
         *file_buffer != some_char)
    current_position++;
  fseek(file_stream, origin, 1);
  return current_position;
}


x86 assembly (clang, -O0):
<find_next_in_filestream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1e(%rbp)
je     118c <find_next_in_filestream+0x5c>
movsbl -0x1d(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    119c <find_next_in_filestream+0x6c>
jmp    11aa <find_next_in_filestream+0x7a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <find_next_in_filestream+0x26>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <fseek@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_next_in_filestream>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %rax,%r15
mov    $0xffffffff,%ebp
lea    0xf(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
add    $0x1,%ebp
test   %rax,%rax
je     1184 <find_next_in_filestream+0x54>
cmp    %r14b,0xf(%rsp)
jne    1160 <find_next_in_filestream+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <fseek@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_next_in_filestream(i32* %0, i8 signext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i64
%6 = alloca i32
%7 = alloca [1 x i8]
store i32* %0, i32** %3
store i8 %1, i8* %4
%8 = load i32*, i32** %3
%9 = call i64 @ftell(i32* %8)
store i64 %9, i64* %5
store i32 0, i32* %6
br label %10
10: ; preds = %24, %2
%11 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i64 @fread(i8* %11, i32 1, i32 1, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br label %22
22: ; preds = %15, %10
%23 = phi i1 [ false, %10 ], [ %21, %15 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %10
27: ; preds = %22
%28 = load i32*, i32** %3
%29 = load i64, i64* %5
%30 = call i32 @fseek(i32* %28, i64 %29, i32 1)
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @find_next_in_filestream(i32* nocapture %0, i8 signext %1) {
%3 = alloca [1 x i8]
%4 = tail call i64 @ftell(i32* %0)
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ 0, %2 ], [ %13, %6 ]
%8 = call i64 @fread(i8* %5, i32 1, i32 1, i32* %0)
%9 = icmp ne i64 %8, 0
%10 = load i8, i8* %5
%11 = icmp ne i8 %10, %1
%12 = select i1 %9, i1 %11, i1 false
%13 = add nuw nsw i32 %7, 1
br i1 %12, label %6, label %14
14: ; preds = %6
%15 = tail call i32 @fseek(i32* %0, i64 %4, i32 1)
ret i32 %7
}