#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 EOF;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void get_str_param(char *p_file, char *p_name, char *param, bool trace) {
  FILE *fp;
  char buff[255];
  char symb[3];
  if ((fp = fopen(p_file, "r")) == NULL) {
    printf("No such file\n");
    exit(1);
  }
  while (42) {
    int ret = fscanf(fp, "%s", buff);
    if (ret == 1) {
      if (buff[0] == '#') {
        fgets(buff, 255, fp);
      } else if (strcmp(buff, p_name) == 0) {
        if (fscanf(fp, "%s %s", symb, param) != 2) {
          printf("No match\n");
          fclose(fp);
          exit(1);
        } else if (strcmp(symb, ":=") != 0) {
          printf("No match\n");
          fclose(fp);
          exit(1);
        } else {
          if (trace) {
            printf("Read value %s = %s\n", p_name, param);
          }
          break;
        }
      }
    } else if (errno != 0) {
      perror("scanf:");
      fclose(fp);
      exit(1);
    } else if (ret == EOF) {
      printf("Couldn't find %s in %s.\n", p_name, p_file);
      break;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<get_str_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11d0 <get_str_param+0x50>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11d5 <get_str_param+0x55>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0x1,-0x138(%rbp)
jne    12f9 <get_str_param+0x179>
movsbl -0x130(%rbp),%eax
cmp    $0x23,%eax
jne    122b <get_str_param+0xab>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
jmp    12f4 <get_str_param+0x174>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12ef <get_str_param+0x16f>
mov    -0x28(%rbp),%rdi
lea    -0x133(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x2,%eax
je     128c <get_str_param+0x10c>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x133(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12ca <get_str_param+0x14a>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12ea <get_str_param+0x16a>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1368 <get_str_param+0x1e8>
jmp    12f4 <get_str_param+0x174>
jmp    1363 <get_str_param+0x1e3>
mov    0x2cd8(%rip),%rax
cmpq   $0x0,(%rax)
je     1329 <get_str_param+0x1a9>
lea    0xd26(%rip),%rdi
call   1090 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x138(%rbp),%eax
mov    0x2cb2(%rip),%rcx
cmp    (%rcx),%eax
jne    1359 <get_str_param+0x1d9>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1368 <get_str_param+0x1e8>
jmp    135e <get_str_param+0x1de>
jmp    1363 <get_str_param+0x1e3>
jmp    11d5 <get_str_param+0x55>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_str_param>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %ecx,0xc(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r14
lea    0xe4c(%rip),%rsi
mov    %rdi,0x18(%rsp)
call   1090 <fopen@plt>
test   %rax,%rax
je     12dd <get_str_param+0x14d>
mov    %rax,%rbx
lea    0xe34(%rip),%rbp
lea    0x20(%rsp),%r12
mov    0x2dfb(%rip),%r15
mov    0x2e04(%rip),%r13
jmp    1200 <get_str_param+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1230 <get_str_param+0xa0>
cmpb   $0x23,0x20(%rsp)
je     11f0 <get_str_param+0x60>
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1200 <get_str_param+0x70>
jmp    1251 <get_str_param+0xc1>
xchg   %ax,%ax
cmpq   $0x0,(%r15)
jne    12bf <get_str_param+0x12f>
cmp    0x0(%r13),%eax
jne    1200 <get_str_param+0x70>
lea    0xddf(%rip),%rdi
mov    %r14,%rsi
mov    0x18(%rsp),%rdx
jmp    129e <get_str_param+0x10e>
lea    0xdaa(%rip),%rsi
lea    0x9(%rsp),%rdx
mov    %rbx,%rdi
mov    0x10(%rsp),%rbp
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    $0x2,%eax
jne    12f3 <get_str_param+0x163>
lea    0xd8d(%rip),%rsi
lea    0x9(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12f3 <get_str_param+0x163>
cmpl   $0x0,0xc(%rsp)
je     12a5 <get_str_param+0x115>
lea    0xd73(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd59(%rip),%rdi
call   10a0 <perror@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
jmp    12cb <get_str_param+0x13b>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [14 x i8] c"No such file\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.4 = [10 x i8] c"No match\0A\00"
@.str.5 = [3 x i8] c":=\00"
@.str.6 = [20 x i8] c"Read value %s = %s\0A\00"
@errno = global i64 0
@.str.7 = [7 x i8] c"scanf:\00"
@EOF = global i32 0
@.str.8 = [25 x i8] c"Couldn't find %s in %s.\0A\00"
define void @get_str_param(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [255 x i8]
%11 = alloca [3 x i8]
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %4
br label %20
20: ; preds = %19, %88
%21 = load i32*, i32** %9
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%23 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %70
26: ; preds = %20
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 35
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%33 = load i32*, i32** %9
%34 = call i32 @fgets(i8* %32, i32 255, i32* %33)
br label %69
35: ; preds = %26
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %68
40: ; preds = %35
%41 = load i32*, i32** %9
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%43 = load i8*, i8** %7
%44 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %43)
%45 = icmp ne i32 %44, 2
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32*, i32** %9
%49 = call i32 @fclose(i32* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %40
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %51
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i8*, i8** %6
%65 = load i8*, i8** %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %64, i8* %65)
br label %67
67: ; preds = %63, %60
br label %89
68: ; preds = %35
br label %69
69: ; preds = %68, %31
br label %88
70: ; preds = %20
%71 = load i64, i64* @errno
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%75 = load i32*, i32** %9
%76 = call i32 @fclose(i32* %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %70
%79 = load i32, i32* %12
%80 = load i32, i32* @EOF
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %86
82: ; preds = %78
%83 = load i8*, i8** %6
%84 = load i8*, i8** %5
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %83, i8* %84)
br label %89
86: ; preds = %78
br label %87
87: ; preds = %86
br label %88
88: ; preds = %87, %69
br label %20
89: ; preds = %82, %67
%90 = load i32*, i32** %9
%91 = call i32 @fclose(i32* %90)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.5 = [3 x i8] c":=\00"
@.str.6 = [20 x i8] c"Read value %s = %s\0A\00"
@errno = global i64 0
@.str.7 = [7 x i8] c"scanf:\00"
@EOF = global i32 0
@.str.8 = [25 x i8] c"Couldn't find %s in %s.\0A\00"
@str.9 = [9 x i8] c"No match\00"
@str.10 = [13 x i8] c"No such file\00"
define void @get_str_param(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [255 x i8]
%6 = alloca [3 x i8]
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4, %25
%15 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %44
17: ; preds = %14
%18 = load i8, i8* %7
%19 = icmp eq i8 %18, 35
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @fgets(i8* %7, i32 255, i32* %9)
br label %25
22: ; preds = %17
%23 = call i64 @strcmp(i8* %7, i8* %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22, %20, %51
br label %14
26: ; preds = %22
%27 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %2)
%28 = icmp eq i32 %27, 2
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
%31 = call i32 @fclose(i32* %9)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
%38 = call i32 @fclose(i32* %9)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %33
%41 = icmp eq i32 %3, 0
br i1 %41, label %56, label %42
42: ; preds = %40
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %1, i8* %2)
br label %56
44: ; preds = %14
%45 = load i64, i64* @errno
%46 = icmp eq i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%49 = call i32 @fclose(i32* %9)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %15, %52
br i1 %53, label %54, label %25
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %1, i8* %0)
br label %56
56: ; preds = %54, %42, %40
%57 = call i32 @fclose(i32* %9)
ret void
}