#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*/ *fgets(char *, int const, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ printf(char *, char const *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
char *read_param_string(FILE **pfp, const char *label, int verbose) {
  const int maxl = 128;
  char line[maxl];
  char st[maxl];
  char *s;
  s = NULL;
  int found = 0;
  FILE *fp;
  fp = *pfp;
  memset(st, 0, maxl * sizeof(char));
  while (((fgets(line, maxl, fp)) != NULL) && !found) {
    if (!strncmp(label, line, strlen(label))) {
      if (!found) {
        sscanf(line, "%*s %s", (char *)&st);
        if (verbose)
          printf("%s = %s\n", label, st);
        found = 1;
      }
    }
  }
  *pfp = fp;
  if (!found)
    return NULL;
  else {
    s = (char *)malloc(sizeof(char) * 256);
    memset(s, 0, 256 * sizeof(char));
    strncpy(s, st, strlen(st));
    return s;
  }
}


x86 assembly (clang, -O0):
<read_param_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x80,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    -0x40(%rbp),%rdx
lea    -0xd0(%rbp),%rdi
mov    $0x80,%esi
call   1080 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x151(%rbp)
je     120a <read_param_string+0x8a>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x151(%rbp)
mov    -0x151(%rbp),%al
test   $0x1,%al
jne    121d <read_param_string+0x9d>
jmp    12a5 <read_param_string+0x125>
mov    -0x18(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    %eax,%edx
lea    -0xd0(%rbp),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12a0 <read_param_string+0x120>
cmpl   $0x0,-0x34(%rbp)
jne    129b <read_param_string+0x11b>
lea    -0xd0(%rbp),%rdi
lea    0xd99(%rip),%rsi
lea    -0x150(%rbp),%rdx
call   10a0 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1294 <read_param_string+0x114>
mov    -0x18(%rbp),%rsi
lea    0xd7f(%rip),%rdi
lea    -0x150(%rbp),%rdx
call   1060 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    12a0 <read_param_string+0x120>
jmp    11d1 <read_param_string+0x51>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,-0x34(%rbp)
jne    12ce <read_param_string+0x14e>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1327 <read_param_string+0x1a7>
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x168(%rbp),%rdi
mov    %eax,%edx
lea    -0x150(%rbp),%rsi
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_param_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edx,0x4(%rsp)
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%r12
lea    0x10(%rsp),%rdi
xor    %r13d,%r13d
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    0x90(%rsp),%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12a6 <read_param_string+0x126>
mov    %rbx,0x8(%rsp)
lea    0x90(%rsp),%rbx
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1240 <read_param_string+0xc0>
test   $0x1,%r15b
jne    1240 <read_param_string+0xc0>
mov    %rbx,%rdi
lea    0xde7(%rip),%rsi
mov    %r14,%rdx
call   10a0 <sscanf@plt>
mov    $0x1,%r13d
cmpl   $0x0,0x4(%rsp)
je     1240 <read_param_string+0xc0>
lea    0xdd2(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %r13d,%r13d
setne  %r15b
test   %rax,%rax
je     1261 <read_param_string+0xe1>
test   %r13d,%r13d
je     11f0 <read_param_string+0x70>
mov    0x8(%rsp),%rax
mov    %r12,(%rax)
test   %r13d,%r13d
je     12a9 <read_param_string+0x129>
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    12ab <read_param_string+0x12b>
mov    %r12,(%rbx)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%*s %s\00"
@.str.1 = [9 x i8] c"%s = %s\0A\00"
define i8* @read_param_string(i32** %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i32** %0, i32*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 128, i32* %8
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 128
%16 = alloca i8, i64 128
store i8* null, i8** %10
store i32 0, i32* %11
%17 = load i32**, i32*** %5
%18 = load i32*, i32** %17
store i32* %18, i32** %12
%19 = call i32 @memset(i8* %16, i32 0, i32 128)
br label %20
20: ; preds = %48, %3
%21 = load i32*, i32** %12
%22 = call i32* @fgets(i8* %15, i32 128, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %11
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br label %28
28: ; preds = %24, %20
%29 = phi i1 [ false, %20 ], [ %27, %24 ]
br i1 %29, label %30, label %49
30: ; preds = %28
%31 = load i8*, i8** %6
%32 = load i8*, i8** %6
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @strncmp(i8* %31, i8* %15, i32 %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %48, label %36
36: ; preds = %30
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %36
%40 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16)
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i8*, i8** %6
%45 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %16)
br label %46
46: ; preds = %43, %39
store i32 1, i32* %11
br label %47
47: ; preds = %46, %36
br label %48
48: ; preds = %47, %30
br label %20
49: ; preds = %28
%50 = load i32*, i32** %12
%51 = load i32**, i32*** %5
store i32* %50, i32** %51
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %49
store i8* null, i8** %4
store i32 1, i32* %13
br label %64
55: ; preds = %49
%56 = call i64 @malloc(i32 256)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = call i32 @memset(i8* %58, i32 0, i32 256)
%60 = load i8*, i8** %10
%61 = call i32 @strlen(i8* %16)
%62 = call i32 @strncpy(i8* %60, i8* %16, i32 %61)
%63 = load i8*, i8** %10
store i8* %63, i8** %4
store i32 1, i32* %13
br label %64
64: ; preds = %55, %54
%65 = load i8*, i8** %9
%66 = load i8*, i8** %4
ret i8* %66
}

LLVM IR (-O2):
@.str = [7 x i8] c"%*s %s\00"
@.str.1 = [9 x i8] c"%s = %s\0A\00"
define i8* @read_param_string(i32** nocapture %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** %0
%9 = call i32 @memset(i8* %6, i32 0, i32 128)
%10 = call i32* @fgets(i8* %7, i32 128, i32* %8)
%11 = icmp eq i32* %10, null
br i1 %11, label %39, label %12
12: ; preds = %3
%13 = icmp eq i32 %2, 0
br label %14
14: ; preds = %12, %25
%15 = phi i1 [ false, %12 ], [ %29, %25 ]
%16 = phi i32 [ 0, %12 ], [ %26, %25 ]
%17 = call i32 @strlen(i8* %1)
%18 = call i32 @strncmp(i8* %1, i8* %7, i32 %17)
%19 = icmp ne i32 %18, 0
%20 = select i1 %19, i1 true, i1 %15
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6)
br i1 %13, label %25, label %23
23: ; preds = %21
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %6)
br label %25
25: ; preds = %21, %23, %14
%26 = phi i32 [ %16, %14 ], [ 1, %23 ], [ 1, %21 ]
%27 = call i32* @fgets(i8* %7, i32 128, i32* %8)
%28 = icmp ne i32* %27, null
%29 = icmp ne i32 %26, 0
%30 = xor i1 %29, true
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %14, label %32
32: ; preds = %25
store i32* %8, i32** %0
br i1 %29, label %33, label %40
33: ; preds = %32
%34 = call i64 @malloc(i32 256)
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @memset(i8* %35, i32 0, i32 256)
%37 = call i32 @strlen(i8* %6)
%38 = call i32 @strncpy(i8* %35, i8* %6, i32 %37)
br label %40
39: ; preds = %3
store i32* %8, i32** %0
br label %40
40: ; preds = %39, %32, %33
%41 = phi i8* [ %35, %33 ], [ null, %32 ], [ null, %39 ]
ret i8* %41
}