#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;
char *fextract(int /*<<< orphan*/ *, long, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long const, int /*<<< orphan*/);
long fstrchr(int /*<<< orphan*/ *, long, char);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *get_icon_path(FILE *stream) {
  char *ipath = NULL;
  const long stream_pos = ftell(stream);
  rewind(stream);
  long start_pos = fstrchr(stream, ftell(stream), '@');
  if (-1 == start_pos) {
    fprintf(stderr, "couldn't find icon path in file\n");
    goto clean_exit;
  }
  long end_pos = fstrchr(stream, ftell(stream), '\n');
  if (-1 == end_pos) {
    fprintf(stderr, "formating error, icon path invalid\n");
    goto clean_exit;
  }
  ipath = fextract(stream, start_pos + 1, end_pos);
clean_exit:
  fseek(stream, stream_pos, SEEK_SET);
  return ipath;
}


x86 assembly (clang, -O0):
<get_icon_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    $0x40,%edx
call   1030 <fstrchr@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x20(%rbp),%rax
jne    11db <get_icon_path+0x7b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1245 <get_icon_path+0xe5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
mov    $0xa,%edx
call   1030 <fstrchr@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x28(%rbp),%rax
jne    122c <get_icon_path+0xcc>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1245 <get_icon_path+0xe5>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rdx
call   1070 <fextract@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_icon_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1060 <ftell@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x40,%edx
call   1030 <fstrchr@plt>
cmp    $0xffffffffffffffff,%rax
je     11ce <get_icon_path+0x6e>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0xa,%edx
call   1030 <fstrchr@plt>
cmp    $0xffffffffffffffff,%rax
je     11e0 <get_icon_path+0x80>
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1070 <fextract@plt>
mov    %rax,%r15
jmp    11f8 <get_icon_path+0x98>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
jmp    11f0 <get_icon_path+0x90>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1050 <fprintf@plt>
xor    %r15d,%r15d
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fseek@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"couldn't find icon path in file\0A\00"
@.str.1 = [36 x i8] c"formating error, icon path invalid\0A\00"
@SEEK_SET = global i32 0
define i8* @get_icon_path(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32* %0, i32** %2
store i8* null, i8** %3
%7 = load i32*, i32** %2
%8 = call i64 @ftell(i32* %7)
store i64 %8, i64* %4
%9 = load i32*, i32** %2
%10 = call i32 @rewind(i32* %9)
%11 = load i32*, i32** %2
%12 = load i32*, i32** %2
%13 = call i64 @ftell(i32* %12)
%14 = call i64 @fstrchr(i32* %11, i64 %13, i8 signext 64)
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = icmp eq i64 -1, %15
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %36
20: ; preds = %1
%21 = load i32*, i32** %2
%22 = load i32*, i32** %2
%23 = call i64 @ftell(i32* %22)
%24 = call i64 @fstrchr(i32* %21, i64 %23, i8 signext 10)
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = icmp eq i64 -1, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %36
30: ; preds = %20
%31 = load i32*, i32** %2
%32 = load i64, i64* %5
%33 = add nsw i64 %32, 1
%34 = load i64, i64* %6
%35 = call i8* @fextract(i32* %31, i64 %33, i64 %34)
store i8* %35, i8** %3
br label %36
36: ; preds = %30, %27, %17
%37 = load i32*, i32** %2
%38 = load i64, i64* %4
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %37, i64 %38, i32 %39)
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"couldn't find icon path in file\0A\00"
@.str.1 = [36 x i8] c"formating error, icon path invalid\0A\00"
@SEEK_SET = global i32 0
define i8* @get_icon_path(i32* %0) {
%2 = tail call i64 @ftell(i32* %0)
%3 = tail call i32 @rewind(i32* %0)
%4 = tail call i64 @ftell(i32* %0)
%5 = tail call i64 @fstrchr(i32* %0, i64 %4, i8 signext 64)
%6 = icmp eq i64 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %20
10: ; preds = %1
%11 = tail call i64 @ftell(i32* %0)
%12 = tail call i64 @fstrchr(i32* %0, i64 %11, i8 signext 10)
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = add nuw nsw i64 %5, 1
%19 = tail call i8* @fextract(i32* %0, i64 %18, i64 %12)
br label %20
20: ; preds = %17, %14, %7
%21 = phi i8* [ null, %7 ], [ null, %14 ], [ %19, %17 ]
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @fseek(i32* %0, i64 %2, i32 %22)
ret i8* %21
}