#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*/ chrswp(char *, char, char, int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ *sopen(char const *, char *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ textutils_strstr(char *, char const *);
int /*<<< orphan*/ trimws(char *);
void get_tokenf(char *dst, char B, char S, char C, const char *tok,
                const char *path) {
  char buffer[1024];
  char *pruned;
  size_t offset;
  FILE *file;
  file = sopen(path, "r");
  while (fgets(buffer, 1024, file)) {
    trimws(buffer);
    if (buffer[0] == C)
      continue;
    if (textutils_strstr(buffer, tok)) {
      offset = strlen(tok) + 1;
      pruned = &buffer[offset];
      chrswp(pruned, C, S, strlen(pruned));
      snprintf(dst, 1024, "%s", pruned);
      break;
    }
  }
  sclose(file);
}


x86 assembly (clang, -O0):
<get_tokenf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <sopen@plt>
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12ba <get_tokenf+0x13a>
lea    -0x420(%rbp),%rdi
call   1090 <trimws@plt>
movsbl -0x420(%rbp),%eax
movsbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
jne    1204 <get_tokenf+0x84>
jmp    11be <get_tokenf+0x3e>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <textutils_strstr@plt>
cmp    $0x0,%rax
je     12b5 <get_tokenf+0x135>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rax
add    -0x430(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0x43a(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x439(%rbp)
mov    -0x428(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x448(%rbp),%rdi
mov    -0x43a(%rbp),%dl
mov    %eax,%ecx
mov    -0x439(%rbp),%al
movsbl %dl,%esi
movsbl %al,%edx
call   1040 <chrswp@plt>
mov    -0x8(%rbp),%rdi
mov    -0x428(%rbp),%rcx
mov    $0x400,%esi
lea    0xd57(%rip),%rdx
call   1070 <snprintf@plt>
jmp    12ba <get_tokenf+0x13a>
jmp    11be <get_tokenf+0x3e>
mov    -0x438(%rbp),%rdi
call   1030 <sclose@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tokenf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %r8,%r12
mov    %ecx,%r13d
mov    %edx,%r15d
mov    %rdi,%r14
lea    0xe5c(%rip),%rsi
mov    %r9,%rdi
call   1060 <sopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1245 <get_tokenf+0xc5>
mov    %rsp,%rbp
jmp    11e5 <get_tokenf+0x65>
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1245 <get_tokenf+0xc5>
mov    %rbp,%rdi
call   1090 <trimws@plt>
cmp    %r13b,(%rsp)
je     11d0 <get_tokenf+0x50>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10a0 <textutils_strstr@plt>
test   %rax,%rax
je     11d0 <get_tokenf+0x50>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
movsbl %r13b,%esi
movsbl %r15b,%edx
mov    %rbp,%rdi
mov    %eax,%ecx
call   1040 <chrswp@plt>
lea    0xdcd(%rip),%rdx
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbp,%rcx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <sclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define void @get_tokenf(i8* %0, i8 signext %1, i8 signext %2, i8 signext %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32*
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i8 %3, i8* %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%17 = load i8*, i8** %12
%18 = call i32* @sopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %16
br label %19
19: ; preds = %55, %33, %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%21 = load i32*, i32** %16
%22 = call i64 @fgets(i8* %20, i32 1024, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %56
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%26 = call i32 @trimws(i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = load i8, i8* %10
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %29, %31
br i1 %32, label %33, label %34
33: ; preds = %24
br label %19
34: ; preds = %24
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%36 = load i8*, i8** %11
%37 = call i64 @textutils_strstr(i8* %35, i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %55
39: ; preds = %34
%40 = load i8*, i8** %11
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
store i64 %43, i64* %15
%44 = load i64, i64* %15
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %44
store i8* %45, i8** %14
%46 = load i8*, i8** %14
%47 = load i8, i8* %10
%48 = load i8, i8* %9
%49 = load i8*, i8** %14
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @chrswp(i8* %46, i8 signext %47, i8 signext %48, i32 %50)
%52 = load i8*, i8** %7
%53 = load i8*, i8** %14
%54 = call i32 @snprintf(i8* %52, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %53)
br label %56
55: ; preds = %34
br label %19
56: ; preds = %39, %19
%57 = load i32*, i32** %16
%58 = call i32 @sclose(i32* %57)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define void @get_tokenf(i8* %0, i8 signext %1, i8 signext %2, i8 signext %3, i8* %4, i8* %5) {
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = tail call i32* @sopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @fgets(i8* %8, i32 1024, i32* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %6, %16
%13 = call i32 @trimws(i8* %8)
%14 = load i8, i8* %8
%15 = icmp eq i8 %14, %3
br i1 %15, label %16, label %19
16: ; preds = %12, %19
%17 = call i64 @fgets(i8* %8, i32 1024, i32* %9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %30, label %12
19: ; preds = %12
%20 = call i64 @textutils_strstr(i8* %8, i8* %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %16, label %22
22: ; preds = %19
%23 = call i32 @strlen(i8* %4)
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %25
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @chrswp(i8* %26, i8 signext %3, i8 signext %2, i32 %27)
%29 = call i32 @snprintf(i8* %0, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %30
30: ; preds = %16, %6, %22
%31 = call i32 @sclose(i32* %9)
ret void
}