#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strstr(char *, char *);
char *strtok(char *, char *);
int getStringFromFile_n(char *file, char *name, char buffer[],
                        int size_buffer) {
  FILE *ptr_file;
  char temp_buf[size_buffer];
  ptr_file = fopen(file, "r");
  if (!ptr_file) {
    printf("Error: Configuration-File not found!\n");
    return -1;
  }
  while (fgets(temp_buf, size_buffer, ptr_file) != NULL) {
    if (temp_buf[0] != '#' && strchr(temp_buf, '=') != NULL &&
        strstr(temp_buf, name)) {
      sprintf(temp_buf, "%s", strtok(temp_buf, "="));
      sprintf(temp_buf, "%s", strtok(NULL, "="));
      break;
    }
  }
  fclose(ptr_file);
  sprintf(buffer, strtok(temp_buf, "\n"));
  return 0;
}


x86 assembly (clang, -O0):
<getStringFromFile_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11fb <getStringFromFile_n+0x7b>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12ea <getStringFromFile_n+0x16a>
jmp    1200 <getStringFromFile_n+0x80>
mov    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ad <getStringFromFile_n+0x12d>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     12a8 <getStringFromFile_n+0x128>
mov    -0x50(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12a8 <getStringFromFile_n+0x128>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12a8 <getStringFromFile_n+0x128>
mov    -0x50(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1080 <strtok@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xda2(%rip),%rsi
call   1080 <strtok@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    12ad <getStringFromFile_n+0x12d>
jmp    1200 <getStringFromFile_n+0x80>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xd5d(%rip),%rsi
call   1080 <strtok@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStringFromFile_n>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r13
mov    %ecx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe3f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1274 <getStringFromFile_n+0xe4>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124c <getStringFromFile_n+0xbc>
cmpb   $0x23,(%rbx)
je     11e0 <getStringFromFile_n+0x50>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e0 <getStringFromFile_n+0x50>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     11e0 <getStringFromFile_n+0x50>
lea    0xde1(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xda9(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strtok@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1285 <getStringFromFile_n+0xf5>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%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 = [38 x i8] c"Error: Configuration-File not found!\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @getStringFromFile_n(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = load i32, i32* %9
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = alloca i8, i64 %15
store i64 %15, i64* %12
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %4
%23 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %13
br label %54
24: ; preds = %4
br label %25
25: ; preds = %47, %24
%26 = load i32, i32* %9
%27 = load i32*, i32** %10
%28 = call i32* @fgets(i8* %17, i32 %26, i32* %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %48
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %17, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 35
br i1 %34, label %35, label %47
35: ; preds = %30
%36 = call i32* @strchr(i8* %17, i8 signext 61)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load i8*, i8** %7
%40 = call i64 @strstr(i8* %17, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %48
47: ; preds = %38, %35, %30
br label %25
48: ; preds = %42, %25
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %8
%52 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* %52)
store i32 0, i32* %5
store i32 1, i32* %13
br label %54
54: ; preds = %48, %22
%55 = load i8*, i8** %11
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [2 x i8] c"\0A\00"
@str = [37 x i8] c"Error: Configuration-File not found!\00"
define i32 @getStringFromFile_n(i8* nocapture %0, i8* %1, i8* nocapture writeonly %2, i32 %3) {
%5 = zext i32 %3 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = call i32* @fgets(i8* %6, i32 %3, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %31, label %14
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %35
14: ; preds = %9, %28
%15 = load i8, i8* %6
%16 = icmp eq i8 %15, 35
br i1 %16, label %28, label %17
17: ; preds = %14
%18 = call i32* @strchr(i8* %6, i8 signext 61)
%19 = icmp eq i32* %18, null
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = call i64 @strstr(i8* %6, i8* %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %24)
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %26)
br label %31
28: ; preds = %20, %17, %14
%29 = call i32* @fgets(i8* %6, i32 %3, i32* %7)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %14
31: ; preds = %28, %9, %23
%32 = call i32 @fclose(i32* %7)
%33 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %33)
br label %35
35: ; preds = %31, %12
%36 = phi i32 [ 0, %31 ], [ -1, %12 ]
ret i32 %36
}