#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*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int find_charn(char *, char, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *read_value_str(FILE *fp, const char *group_name, const char *key_name,
                     char *data) {
  if (fp == NULL || group_name == NULL || key_name == NULL || data == NULL)
    return NULL;
  rewind(fp);
  char group[140];
  char key[140];
  char value[140];
  char buffer[140];
  char *result = NULL;
  int index = -1;
  char group_found_flag = 0;
  while (!feof(fp)) {
    memset(buffer, 0, 140 * sizeof(char));
    result = fgets(buffer, 140, fp);
    if (result == NULL)
      break;
    if (buffer[0] == '[') {
      memset(group, 0, 140 * sizeof(char));
      index = find_charn(buffer, ']', 140);
      if (index != -1) {
        strncpy(group, buffer + 1, index - 1);
        if (strcmp(group, group_name) == 0) {
          group_found_flag = 1;
        } else {
          group_found_flag = 0;
        }
      }
      continue;
    }
    index = find_charn(buffer, '=', 140);
    if (index != -1) {
      memset(key, 0, 140 * sizeof(char));
      memset(value, 0, 140 * sizeof(char));
      strncpy(key, buffer, index);
      strncpy(value, buffer + index + 1, 140);
      if (group_found_flag == 1 && strcmp(key, key_name) == 0) {
        strncpy(data, value, 140);
        return data;
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<read_value_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b7 <read_value_str+0x47>
cmpq   $0x0,-0x18(%rbp)
je     11b7 <read_value_str+0x47>
cmpq   $0x0,-0x20(%rbp)
je     11b7 <read_value_str+0x47>
cmpq   $0x0,-0x28(%rbp)
jne    11c4 <read_value_str+0x54>
movq   $0x0,-0x8(%rbp)
jmp    13d8 <read_value_str+0x268>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
movq   $0x0,-0x278(%rbp)
movl   $0xffffffff,-0x27c(%rbp)
ff ff ff
movb   $0x0,-0x27d(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1207 <read_value_str+0x97>
jmp    13d0 <read_value_str+0x260>
lea    -0x270(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
lea    -0x270(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x8c,%esi
call   1060 <fgets@plt>
mov    %rax,-0x278(%rbp)
cmpq   $0x0,-0x278(%rbp)
jne    1249 <read_value_str+0xd9>
jmp    13d0 <read_value_str+0x260>
movsbl -0x270(%rbp),%eax
cmp    $0x5b,%eax
jne    12ec <read_value_str+0x17c>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
lea    -0x270(%rbp),%rdi
mov    $0x5d,%esi
mov    $0x8c,%edx
call   1070 <find_charn@plt>
mov    %eax,-0x27c(%rbp)
cmpl   $0xffffffff,-0x27c(%rbp)
je     12e7 <read_value_str+0x177>
lea    -0xc0(%rbp),%rdi
lea    -0x270(%rbp),%rsi
add    $0x1,%rsi
mov    -0x27c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12db <read_value_str+0x16b>
movb   $0x1,-0x27d(%rbp)
jmp    12e2 <read_value_str+0x172>
movb   $0x0,-0x27d(%rbp)
jmp    12e7 <read_value_str+0x177>
jmp    11e9 <read_value_str+0x79>
lea    -0x270(%rbp),%rdi
mov    $0x3d,%esi
mov    $0x8c,%edx
call   1070 <find_charn@plt>
mov    %eax,-0x27c(%rbp)
cmpl   $0xffffffff,-0x27c(%rbp)
je     13cb <read_value_str+0x25b>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
lea    -0x150(%rbp),%rdi
lea    -0x270(%rbp),%rsi
mov    -0x27c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x1e0(%rbp),%rdi
lea    -0x270(%rbp),%rsi
movslq -0x27c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
movsbl -0x27d(%rbp),%eax
cmp    $0x1,%eax
jne    13c6 <read_value_str+0x256>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13c6 <read_value_str+0x256>
mov    -0x28(%rbp),%rdi
lea    -0x1e0(%rbp),%rsi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13d8 <read_value_str+0x268>
jmp    13cb <read_value_str+0x25b>
jmp    11e9 <read_value_str+0x79>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_value_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
xor    %eax,%eax
test   %rdi,%rdi
je     11b6 <read_value_str+0x46>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11b6 <read_value_str+0x46>
mov    %rdx,%r15
test   %rdx,%rdx
je     11b6 <read_value_str+0x46>
mov    %rcx,%r14
test   %rcx,%rcx
je     11b6 <read_value_str+0x46>
mov    %rdi,%rbx
call   1040 <rewind@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11c8 <read_value_str+0x58>
xor    %eax,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,0x18(%rsp)
mov    %rbp,0x10(%rsp)
mov    %r14,0x8(%rsp)
lea    0x20(%rsp),%r15
lea    0x1d0(%rsp),%rbp
xor    %eax,%eax
mov    %rax,(%rsp)
jmp    11fc <read_value_str+0x8c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11b4 <read_value_str+0x44>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x8c,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11b4 <read_value_str+0x44>
cmpb   $0x5b,0x20(%rsp)
je     12c0 <read_value_str+0x150>
mov    %r15,%rdi
mov    $0x3d,%esi
mov    $0x8c,%edx
call   1070 <find_charn@plt>
cmp    $0xffffffff,%eax
je     11f0 <read_value_str+0x80>
mov    %eax,%r12d
lea    0x140(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
lea    0xb0(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x21,%rsi
mov    %r14,%rdi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
cmpb   $0x1,(%rsp)
jne    11f0 <read_value_str+0x80>
lea    0x140(%rsp),%rdi
mov    0x18(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11f0 <read_value_str+0x80>
jmp    1329 <read_value_str+0x1b9>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1050 <memset@plt>
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x8c,%edx
call   1070 <find_charn@plt>
cmp    $0xffffffff,%eax
je     130f <read_value_str+0x19f>
add    $0xffffffff,%eax
mov    %rbp,%rdi
lea    0x21(%rsp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
sete   %al
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
mov    $0x0,%eax
je     11fc <read_value_str+0x8c>
jmp    11b6 <read_value_str+0x46>
lea    0xb0(%rsp),%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rax
jmp    11b6 <read_value_str+0x46>

LLVM IR (-O0):
define i8* @read_value_str(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [140 x i8]
%11 = alloca [140 x i8]
%12 = alloca [140 x i8]
%13 = alloca [140 x i8]
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %28, label %19
19: ; preds = %4
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i8*, i8** %8
%24 = icmp eq i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %9
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %25, %22, %19, %4
store i8* null, i8** %5
br label %110
29: ; preds = %25
%30 = load i32*, i32** %6
%31 = call i32 @rewind(i32* %30)
store i8* null, i8** %14
store i32 -1, i32* %15
store i8 0, i8* %16
br label %32
32: ; preds = %108, %72, %29
%33 = load i32*, i32** %6
%34 = call i32 @feof(i32* %33)
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %109
37: ; preds = %32
%38 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 140)
%40 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%41 = load i32*, i32** %6
%42 = call i8* @fgets(i8* %40, i32 140, i32* %41)
store i8* %42, i8** %14
%43 = load i8*, i8** %14
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %37
br label %109
46: ; preds = %37
%47 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 91
br i1 %50, label %51, label %73
51: ; preds = %46
%52 = getelementptr inbounds [140 x i8], [140 x i8]* %10, i64 0, i64 0
%53 = call i32 @memset(i8* %52, i32 0, i32 140)
%54 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%55 = call i32 @find_charn(i8* %54, i8 signext 93, i32 140)
store i32 %55, i32* %15
%56 = load i32, i32* %15
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %72
58: ; preds = %51
%59 = getelementptr inbounds [140 x i8], [140 x i8]* %10, i64 0, i64 0
%60 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i32, i32* %15
%63 = sub nsw i32 %62, 1
%64 = call i32 @strncpy(i8* %59, i8* %61, i32 %63)
%65 = getelementptr inbounds [140 x i8], [140 x i8]* %10, i64 0, i64 0
%66 = load i8*, i8** %7
%67 = call i64 @strcmp(i8* %65, i8* %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %58
store i8 1, i8* %16
br label %71
70: ; preds = %58
store i8 0, i8* %16
br label %71
71: ; preds = %70, %69
br label %72
72: ; preds = %71, %51
br label %32
73: ; preds = %46
%74 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%75 = call i32 @find_charn(i8* %74, i8 signext 61, i32 140)
store i32 %75, i32* %15
%76 = load i32, i32* %15
%77 = icmp ne i32 %76, -1
br i1 %77, label %78, label %108
78: ; preds = %73
%79 = getelementptr inbounds [140 x i8], [140 x i8]* %11, i64 0, i64 0
%80 = call i32 @memset(i8* %79, i32 0, i32 140)
%81 = getelementptr inbounds [140 x i8], [140 x i8]* %12, i64 0, i64 0
%82 = call i32 @memset(i8* %81, i32 0, i32 140)
%83 = getelementptr inbounds [140 x i8], [140 x i8]* %11, i64 0, i64 0
%84 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%85 = load i32, i32* %15
%86 = call i32 @strncpy(i8* %83, i8* %84, i32 %85)
%87 = getelementptr inbounds [140 x i8], [140 x i8]* %12, i64 0, i64 0
%88 = getelementptr inbounds [140 x i8], [140 x i8]* %13, i64 0, i64 0
%89 = load i32, i32* %15
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = getelementptr inbounds i8, i8* %91, i64 1
%93 = call i32 @strncpy(i8* %87, i8* %92, i32 140)
%94 = load i8, i8* %16
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 1
br i1 %96, label %97, label %107
97: ; preds = %78
%98 = getelementptr inbounds [140 x i8], [140 x i8]* %11, i64 0, i64 0
%99 = load i8*, i8** %8
%100 = call i64 @strcmp(i8* %98, i8* %99)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %107
102: ; preds = %97
%103 = load i8*, i8** %9
%104 = getelementptr inbounds [140 x i8], [140 x i8]* %12, i64 0, i64 0
%105 = call i32 @strncpy(i8* %103, i8* %104, i32 140)
%106 = load i8*, i8** %9
store i8* %106, i8** %5
br label %110
107: ; preds = %97, %78
br label %108
108: ; preds = %107, %73
br label %32
109: ; preds = %45, %32
store i8* null, i8** %5
br label %110
110: ; preds = %109, %102, %28
%111 = load i8*, i8** %5
ret i8* %111
}

LLVM IR (-O2):
define i8* @read_value_str(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [140 x i8]
%6 = alloca [140 x i8]
%7 = alloca [140 x i8]
%8 = alloca [140 x i8]
%9 = icmp eq i32* %0, null
%10 = icmp eq i8* %1, null
%11 = or i1 %9, %10
%12 = icmp eq i8* %2, null
%13 = or i1 %11, %12
%14 = icmp eq i8* %3, null
%15 = or i1 %13, %14
br i1 %15, label %71, label %16
16: ; preds = %4
%17 = tail call i32 @rewind(i32* %0)
%18 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [140 x i8], [140 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [140 x i8], [140 x i8]* %8, i64 0, i64 0
%22 = call i32 @feof(i32* %0)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %69
24: ; preds = %16
%25 = getelementptr inbounds [140 x i8], [140 x i8]* %8, i64 0, i64 1
br label %26
26: ; preds = %24, %46
%27 = phi i8 [ 0, %24 ], [ %47, %46 ]
%28 = icmp eq i8 %27, 1
br label %29
29: ; preds = %26, %66
%30 = call i32 @memset(i8* %21, i32 0, i32 140)
%31 = call i8* @fgets(i8* %21, i32 140, i32* %0)
%32 = icmp eq i8* %31, null
br i1 %32, label %69, label %33
33: ; preds = %29
%34 = load i8, i8* %21
%35 = icmp eq i8 %34, 91
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = call i32 @memset(i8* %18, i32 0, i32 140)
%38 = call i32 @find_charn(i8* %21, i8 signext 93, i32 140)
%39 = icmp eq i32 %38, -1
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = add nsw i32 %38, -1
%42 = call i32 @strncpy(i8* %18, i8* %25, i32 %41)
%43 = call i64 @strcmp(i8* %18, i8* %1)
%44 = icmp eq i64 %43, 0
%45 = zext i1 %44 to i8
br label %46
46: ; preds = %40, %36
%47 = phi i8 [ %27, %36 ], [ %45, %40 ]
%48 = call i32 @feof(i32* %0)
%49 = icmp eq i32 %48, 0
br i1 %49, label %26, label %69
50: ; preds = %33
%51 = call i32 @find_charn(i8* %21, i8 signext 61, i32 140)
%52 = icmp eq i32 %51, -1
br i1 %52, label %66, label %53
53: ; preds = %50
%54 = call i32 @memset(i8* %19, i32 0, i32 140)
%55 = call i32 @memset(i8* %20, i32 0, i32 140)
%56 = call i32 @strncpy(i8* %19, i8* %21, i32 %51)
%57 = sext i32 %51 to i64
%58 = getelementptr inbounds [140 x i8], [140 x i8]* %8, i64 0, i64 %57
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = call i32 @strncpy(i8* %20, i8* %59, i32 140)
br i1 %28, label %61, label %66
61: ; preds = %53
%62 = call i64 @strcmp(i8* %19, i8* %2)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @strncpy(i8* %3, i8* %20, i32 140)
br label %69
66: ; preds = %53, %61, %50
%67 = call i32 @feof(i32* %0)
%68 = icmp eq i32 %67, 0
br i1 %68, label %29, label %69
69: ; preds = %46, %29, %66, %16, %64
%70 = phi i8* [ %3, %64 ], [ null, %16 ], [ null, %66 ], [ null, %29 ], [ null, %46 ]
br label %71
71: ; preds = %4, %69
%72 = phi i8* [ %70, %69 ], [ null, %4 ]
ret i8* %72
}