#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*/ log_entry(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) {
    log_entry("modbus_to_mqtt_gateway", "Error: Configuration-File not found");
    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    0xe28(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    121e <getStringFromFile_n+0x8e>
lea    0xe0f(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <log_entry@plt>
lea    0xe37(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    130d <getStringFromFile_n+0x17d>
jmp    1223 <getStringFromFile_n+0x93>
mov    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12d0 <getStringFromFile_n+0x140>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     12cb <getStringFromFile_n+0x13b>
mov    -0x50(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12cb <getStringFromFile_n+0x13b>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     12cb <getStringFromFile_n+0x13b>
mov    -0x50(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1090 <strtok@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdba(%rip),%rsi
call   1090 <strtok@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    12d0 <getStringFromFile_n+0x140>
jmp    1223 <getStringFromFile_n+0x93>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xd75(%rip),%rsi
call   1090 <strtok@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
mov    $0x0,%al
call   10a0 <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    0xe2f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1284 <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     125c <getStringFromFile_n+0xbc>
cmpb   $0x23,(%rbx)
je     11f0 <getStringFromFile_n+0x50>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f0 <getStringFromFile_n+0x50>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     11f0 <getStringFromFile_n+0x50>
lea    0xe0c(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   10a0 <strtok@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xdd4(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strtok@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10b0 <sprintf@plt>
jmp    12a8 <getStringFromFile_n+0x108>
lea    0xd77(%rip),%rdi
lea    0xd87(%rip),%rsi
call   1080 <log_entry@plt>
lea    0xda3(%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 = [23 x i8] c"modbus_to_mqtt_gateway\00"
@.str.2 = [36 x i8] c"Error: Configuration-File not found\00"
@.str.3 = [38 x i8] c"Error: Configuration-File not found!\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"=\00"
@.str.6 = [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 %25, label %22
22: ; preds = %4
%23 = call i32 @log_entry(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %13
br label %55
25: ; preds = %4
br label %26
26: ; preds = %48, %25
%27 = load i32, i32* %9
%28 = load i32*, i32** %10
%29 = call i32* @fgets(i8* %17, i32 %27, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %49
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %17, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 35
br i1 %35, label %36, label %48
36: ; preds = %31
%37 = call i32* @strchr(i8* %17, i8 signext 61)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = call i64 @strstr(i8* %17, i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %49
48: ; preds = %39, %36, %31
br label %26
49: ; preds = %43, %26
%50 = load i32*, i32** %10
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %8
%53 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %52, i8* %53)
store i32 0, i32* %5
store i32 1, i32* %13
br label %55
55: ; preds = %49, %22
%56 = load i8*, i8** %11
%57 = load i32, i32* %5
ret i32 %57
}

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