#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*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void parse_and_print(FILE *fp) {
  if (fp == NULL)
    return;
  rewind(fp);
  char group[140];
  char key[140];
  char value[140];
  char buffer[140];
  char *result = NULL;
  int index = -1;
  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);
        printf("GROUP: %s\n", group);
      }
      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);
      printf("KEY: %s\n", key);
      printf("VALUE: %s\n", value);
    }
  }
}


x86 assembly (clang, -O0):
<parse_and_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118f <parse_and_print+0x1f>
jmp    134a <parse_and_print+0x1da>
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
movq   $0x0,-0x258(%rbp)
movl   $0xffffffff,-0x25c(%rbp)
ff ff ff
mov    -0x8(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <parse_and_print+0x5b>
jmp    134a <parse_and_print+0x1da>
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
lea    -0x250(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x8c,%esi
call   1070 <fgets@plt>
mov    %rax,-0x258(%rbp)
cmpq   $0x0,-0x258(%rbp)
jne    120d <parse_and_print+0x9d>
jmp    134a <parse_and_print+0x1da>
movsbl -0x250(%rbp),%eax
cmp    $0x5b,%eax
jne    1291 <parse_and_print+0x121>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
lea    -0x250(%rbp),%rdi
mov    $0x5d,%esi
mov    $0x8c,%edx
call   1080 <find_charn@plt>
mov    %eax,-0x25c(%rbp)
cmpl   $0xffffffff,-0x25c(%rbp)
je     128c <parse_and_print+0x11c>
lea    -0xa0(%rbp),%rdi
lea    -0x250(%rbp),%rsi
add    $0x1,%rsi
mov    -0x25c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd79(%rip),%rdi
call   1040 <printf@plt>
jmp    11ad <parse_and_print+0x3d>
lea    -0x250(%rbp),%rdi
mov    $0x3d,%esi
mov    $0x8c,%edx
call   1080 <find_charn@plt>
mov    %eax,-0x25c(%rbp)
cmpl   $0xffffffff,-0x25c(%rbp)
je     1345 <parse_and_print+0x1d5>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
lea    -0x1c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
lea    -0x130(%rbp),%rdi
lea    -0x250(%rbp),%rsi
mov    -0x25c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x1c0(%rbp),%rdi
lea    -0x250(%rbp),%rsi
movslq -0x25c(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
lea    -0x130(%rbp),%rsi
lea    0xcde(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1c0(%rbp),%rsi
lea    0xcd4(%rip),%rdi
call   1040 <printf@plt>
jmp    11ad <parse_and_print+0x3d>
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_and_print>:
test   %rdi,%rdi
je     11ab <parse_and_print+0x3b>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %rdi,%rbx
call   1050 <rewind@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11ac <parse_and_print+0x3c>
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r15
lea    0x1b0(%rsp),%r12
lea    0x120(%rsp),%rbp
lea    0x90(%rsp),%r14
jmp    1227 <parse_and_print+0xb7>
nopl   0x0(%rax)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x8c,%edx
call   1080 <find_charn@plt>
cmp    $0xffffffff,%eax
je     1217 <parse_and_print+0xa7>
add    $0xffffffff,%eax
mov    %r12,%rdi
lea    0x1(%rsp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    0xdf1(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    119a <parse_and_print+0x2a>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    $0x8c,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     119a <parse_and_print+0x2a>
cmpb   $0x5b,(%rsp)
je     11d0 <parse_and_print+0x60>
mov    %r15,%rdi
mov    $0x3d,%esi
mov    $0x8c,%edx
call   1080 <find_charn@plt>
cmp    $0xffffffff,%eax
je     1217 <parse_and_print+0xa7>
mov    %eax,%r13d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8c,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <strncpy@plt>
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x1,%rsi
mov    %r14,%rdi
mov    $0x8c,%edx
call   1030 <strncpy@plt>
lea    0xd4d(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
lea    0xd47(%rip),%rdi
mov    %r14,%rsi
jmp    1212 <parse_and_print+0xa2>

LLVM IR (-O0):
@.str = [11 x i8] c"GROUP: %s\0A\00"
@.str.1 = [9 x i8] c"KEY: %s\0A\00"
@.str.2 = [11 x i8] c"VALUE: %s\0A\00"
define void @parse_and_print(i32* %0) {
%2 = alloca i32*
%3 = alloca [140 x i8]
%4 = alloca [140 x i8]
%5 = alloca [140 x i8]
%6 = alloca [140 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
br label %77
12: ; preds = %1
%13 = load i32*, i32** %2
%14 = call i32 @rewind(i32* %13)
store i8* null, i8** %7
store i32 -1, i32* %8
br label %15
15: ; preds = %76, %50, %12
%16 = load i32*, i32** %2
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %77
20: ; preds = %15
%21 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 140)
%23 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %2
%25 = call i8* @fgets(i8* %23, i32 140, i32* %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %20
br label %77
29: ; preds = %20
%30 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 91
br i1 %33, label %34, label %51
34: ; preds = %29
%35 = getelementptr inbounds [140 x i8], [140 x i8]* %3, i64 0, i64 0
%36 = call i32 @memset(i8* %35, i32 0, i32 140)
%37 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%38 = call i32 @find_charn(i8* %37, i8 signext 93, i32 140)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %50
41: ; preds = %34
%42 = getelementptr inbounds [140 x i8], [140 x i8]* %3, i64 0, i64 0
%43 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i32, i32* %8
%46 = sub nsw i32 %45, 1
%47 = call i32 @strncpy(i8* %42, i8* %44, i32 %46)
%48 = getelementptr inbounds [140 x i8], [140 x i8]* %3, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %41, %34
br label %15
51: ; preds = %29
%52 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%53 = call i32 @find_charn(i8* %52, i8 signext 61, i32 140)
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, -1
br i1 %55, label %56, label %76
56: ; preds = %51
%57 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%58 = call i32 @memset(i8* %57, i32 0, i32 140)
%59 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 0
%60 = call i32 @memset(i8* %59, i32 0, i32 140)
%61 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%62 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%63 = load i32, i32* %8
%64 = call i32 @strncpy(i8* %61, i8* %62, i32 %63)
%65 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 0
%66 = getelementptr inbounds [140 x i8], [140 x i8]* %6, i64 0, i64 0
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = call i32 @strncpy(i8* %65, i8* %70, i32 140)
%72 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %72)
%74 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 0
%75 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %56, %51
br label %15
77: ; preds = %11, %28, %15
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"GROUP: %s\0A\00"
@.str.1 = [9 x i8] c"KEY: %s\0A\00"
@.str.2 = [11 x i8] c"VALUE: %s\0A\00"
define void @parse_and_print(i32* %0) {
%2 = alloca [140 x i8]
%3 = alloca [140 x i8]
%4 = alloca [140 x i8]
%5 = alloca [140 x i8]
%6 = icmp eq i32* %0, null
br i1 %6, label %49, label %7
7: ; preds = %1
%8 = tail call i32 @rewind(i32* %0)
%9 = getelementptr inbounds [140 x i8], [140 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [140 x i8], [140 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 0
%13 = call i32 @feof(i32* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %48
15: ; preds = %7
%16 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 1
br label %17
17: ; preds = %15, %32
%18 = call i32 @memset(i8* %12, i32 0, i32 140)
%19 = call i8* @fgets(i8* %12, i32 140, i32* %0)
%20 = icmp eq i8* %19, null
br i1 %20, label %48, label %21
21: ; preds = %17
%22 = load i8, i8* %12
%23 = icmp eq i8 %22, 91
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = call i32 @memset(i8* %9, i32 0, i32 140)
%26 = call i32 @find_charn(i8* %12, i8 signext 93, i32 140)
%27 = icmp eq i32 %26, -1
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = add nsw i32 %26, -1
%30 = call i32 @strncpy(i8* %9, i8* %16, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %32
32: ; preds = %35, %38, %24, %28
%33 = call i32 @feof(i32* %0)
%34 = icmp eq i32 %33, 0
br i1 %34, label %17, label %48
35: ; preds = %21
%36 = call i32 @find_charn(i8* %12, i8 signext 61, i32 140)
%37 = icmp eq i32 %36, -1
br i1 %37, label %32, label %38
38: ; preds = %35
%39 = call i32 @memset(i8* %10, i32 0, i32 140)
%40 = call i32 @memset(i8* %11, i32 0, i32 140)
%41 = call i32 @strncpy(i8* %10, i8* %12, i32 %36)
%42 = sext i32 %36 to i64
%43 = getelementptr inbounds [140 x i8], [140 x i8]* %5, i64 0, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i32 @strncpy(i8* %11, i8* %44, i32 140)
%46 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %32
48: ; preds = %32, %17, %7
br label %49
49: ; preds = %1, %48
ret void
}