#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*/ path;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncasecmp(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int miread_cfg(const char *name, char *buffer, int maxlen) {
  FILE *fp;
  int result = 0;
  char *home_ptr = getenv("HOME");
  char path[256];
  if (home_ptr != NULL) {
    strncpy(path, home_ptr, sizeof(path) - 1);
  } else {
    path[0] = '\0';
  }
  strcat(path, "/.mincrc");
  if ((fp = fopen(path, "r")) != NULL) {
    while (fgets(buffer, maxlen, fp)) {
      if (buffer[0] == '#') {
        continue;
      }
      if (!strncasecmp(buffer, name, strlen(name))) {
        char *tmp = strchr(buffer, '=');
        if (tmp != NULL) {
          tmp++;
          while (isspace(*tmp)) {
            tmp++;
          }
          strncpy(buffer, tmp, maxlen);
          result = 1;
          break;
        }
      }
    }
    fclose(fp);
  }
  return (result);
}


x86 assembly (clang, -O0):
<miread_cfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11f2 <miread_cfg+0x52>
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xff,%edx
call   1040 <strncpy@plt>
jmp    11f9 <miread_cfg+0x59>
movb   $0x0,-0x130(%rbp)
lea    -0x130(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x130(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1335 <miread_cfg+0x195>
jmp    1232 <miread_cfg+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     132c <miread_cfg+0x18c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1261 <miread_cfg+0xc1>
jmp    1232 <miread_cfg+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1327 <miread_cfg+0x187>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
je     1322 <miread_cfg+0x182>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     1303 <miread_cfg+0x163>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    12d3 <miread_cfg+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
movl   $0x1,-0x24(%rbp)
jmp    132c <miread_cfg+0x18c>
jmp    1327 <miread_cfg+0x187>
jmp    1232 <miread_cfg+0x92>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<miread_cfg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe3f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11dd <miread_cfg+0x3d>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0xff,%edx
call   1040 <strncpy@plt>
jmp    11e1 <miread_cfg+0x41>
movb   $0x0,(%rsp)
lea    0xe1d(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10c0 <strcat@plt>
lea    0xe14(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b0 <miread_cfg+0x110>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
xor    %r12d,%r12d
jmp    123e <miread_cfg+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12a6 <miread_cfg+0x106>
cmpb   $0x23,(%rbx)
je     1230 <miread_cfg+0x90>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10a0 <strncasecmp@plt>
test   %eax,%eax
jne    1230 <miread_cfg+0x90>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1230 <miread_cfg+0x90>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1080 <isspace@plt>
test   %rax,%rax
jne    1280 <miread_cfg+0xe0>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <strncpy@plt>
mov    $0x1,%r12d
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    12b3 <miread_cfg+0x113>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [9 x i8] c"/.mincrc\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @miread_cfg(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [256 x i8]
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %9
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 255)
br label %21
19: ; preds = %3
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8 0, i8* %20
br label %21
21: ; preds = %19, %15
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %7
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %74
27: ; preds = %21
br label %28
28: ; preds = %70, %40, %27
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = load i32*, i32** %7
%32 = call i64 @fgets(i8* %29, i32 %30, i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %71
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 35
br i1 %39, label %40, label %41
40: ; preds = %34
br label %28
41: ; preds = %34
%42 = load i8*, i8** %5
%43 = load i8*, i8** %4
%44 = load i8*, i8** %4
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @strncasecmp(i8* %42, i8* %43, i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %70, label %48
48: ; preds = %41
%49 = load i8*, i8** %5
%50 = call i8* @strchr(i8* %49, i8 signext 61)
store i8* %50, i8** %11
%51 = load i8*, i8** %11
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %69
53: ; preds = %48
%54 = load i8*, i8** %11
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %11
br label %56
56: ; preds = %61, %53
%57 = load i8*, i8** %11
%58 = load i8, i8* %57
%59 = call i64 @isspace(i8 signext %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %11
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %11
br label %56
64: ; preds = %56
%65 = load i8*, i8** %5
%66 = load i8*, i8** %11
%67 = load i32, i32* %6
%68 = call i32 @strncpy(i8* %65, i8* %66, i32 %67)
store i32 1, i32* %8
br label %71
69: ; preds = %48
br label %70
70: ; preds = %69, %41
br label %28
71: ; preds = %64, %28
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %71, %21
%75 = load i32, i32* %8
ret i32 %75
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [9 x i8] c"/.mincrc\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @miread_cfg(i8* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %5, null
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 @strncpy(i8* %6, i8* %5, i32 255)
br label %11
10: ; preds = %3
store i8 0, i8* %6
br label %11
11: ; preds = %10, %8
%12 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %42, label %15
15: ; preds = %11
%16 = call i64 @fgets(i8* %1, i32 %2, i32* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %39, label %18
18: ; preds = %15, %36
%19 = load i8, i8* %1
%20 = icmp eq i8 %19, 35
br i1 %20, label %36, label %21
21: ; preds = %18
%22 = call i32 @strlen(i8* %0)
%23 = call i32 @strncasecmp(i8* %1, i8* %0, i32 %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = call i8* @strchr(i8* %1, i8 signext 61)
%27 = icmp eq i8* %26, null
br i1 %27, label %36, label %28
28: ; preds = %25, %28
%29 = phi i8* [ %30, %28 ], [ %26, %25 ]
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = call i64 @isspace(i8 signext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %28
34: ; preds = %28
%35 = call i32 @strncpy(i8* %1, i8* %30, i32 %2)
br label %39
36: ; preds = %21, %25, %18
%37 = call i64 @fgets(i8* %1, i32 %2, i32* %13)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %18
39: ; preds = %36, %15, %34
%40 = phi i32 [ 1, %34 ], [ 0, %15 ], [ 0, %36 ]
%41 = call i32 @fclose(i32* %13)
br label %42
42: ; preds = %39, %11
%43 = phi i32 [ %40, %39 ], [ 0, %11 ]
ret i32 %43
}