#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*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ logerror(char *, int, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *strstr(char *, char const *);
void getvarconf(const char *var, char **re) {
  FILE *ft = fopen("/etc/haarp/haarp.conf", "r");
  if (!ft) {
    logerror("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/keikurono/haarp-ext-js-viewer/refs/"
             "heads/master/src/utils.c",
             13, "Error, config file /etc/haarp/haarp.conf not found!");
    exit(1);
  }
  char line[200];
  char *l;
  strcpy(*re, "\0");
  while (fgets(line, 200, ft)) {
    l = strstr(line, var);
    if (l) {
      sscanf(l + strlen(var), "%s", *re);
      return;
    }
  }
}


x86 assembly (clang, -O0):
<getvarconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <getvarconf+0x57>
lea    0xe5c(%rip),%rdi
mov    $0xd,%esi
lea    0xee6(%rip),%rdx
call   1060 <logerror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xf00(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     126e <getvarconf+0xee>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0xe8(%rbp)
je     1269 <getvarconf+0xe9>
mov    -0xe8(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf0(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe83(%rip),%rsi
call   1070 <sscanf@plt>
jmp    126e <getvarconf+0xee>
jmp    11ea <getvarconf+0x6a>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getvarconf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe63(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1228 <getvarconf+0xa8>
mov    %rax,%r12
mov    (%r14),%rdi
lea    0xf2a(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1217 <getvarconf+0x97>
mov    %r13,%rdi
mov    %r15,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11d0 <getvarconf+0x50>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
mov    (%r14),%rdx
lea    0xed3(%rip),%rsi
mov    %rbx,%rdi
call   1070 <sscanf@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde9(%rip),%rdi
lea    0xe78(%rip),%rdx
mov    $0xd,%esi
call   1060 <logerror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/etc/haarp/haarp.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/keikurono/haarp-ext-js-viewer/refs/heads/master/src/utils.c\00"
@.str.3 = [52 x i8] c"Error, config file /etc/haarp/haarp.conf not found!\00"
@.str.4 = [2 x i8] zeroinitializer
@.str.5 = [3 x i8] c"%s\00"
define void @getvarconf(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [200 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @logerror(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str.2, i64 0, i64 0), i32 13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %38, %14
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i64 @fgets(i8* %19, i32 200, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i8* @strstr(i8* %24, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %39
38: ; preds = %23
br label %18
39: ; preds = %29, %18
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"/etc/haarp/haarp.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [150 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/keikurono/haarp-ext-js-viewer/refs/heads/master/src/utils.c\00"
@.str.3 = [52 x i8] c"Error, config file /etc/haarp/haarp.conf not found!\00"
@.str.4 = [2 x i8] zeroinitializer
@.str.5 = [3 x i8] c"%s\00"
define void @getvarconf(i8* %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @logerror(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str.2, i64 0, i64 0), i32 13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %1
%12 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %16, %9
%14 = call i64 @fgets(i8* %10, i32 200, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = call i8* @strstr(i8* %10, i8* dereferenceable(1) %0)
%18 = icmp eq i8* %17, null
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = load i8*, i8** %1
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %13, %19
ret void
}