#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
char *strchr(char *, char);
char *strstr(char *, char const *);
int item_read(const char *cfg_fname, const char *key, char *value, int *len) {
  int ret = 0;
  FILE *fp = NULL;
  char linebuf[2048];
  char *ptmp, *pbegin;
  if (cfg_fname == NULL || key == NULL || value == NULL) {
    ret = -1;
    printf("item_read error, param error\n");
  }
  fp = fopen(cfg_fname, "r");
  if (fp == NULL) {
    ret = -2;
    printf("item_read error, param error\n");
  }
  while (!feof(fp)) {
    memset(linebuf, 0, 2048);
    fgets(linebuf, 2048, fp);
    ptmp = strstr(linebuf, key);
    if (ptmp == NULL)
      continue;
    ptmp = strchr(linebuf, '=');
    if (ptmp == NULL)
      continue;
    while (*++ptmp == ' ')
      ;
    pbegin = ptmp;
    if (*pbegin == '\n')
      goto out;
    while (*ptmp != ' ' && *ptmp != '\n')
      ptmp++;
    *len = ptmp - pbegin;
    memcpy(value, pbegin, *len);
  }
out:
  if (fp != NULL)
    fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<item_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11db <item_read+0x4b>
cmpq   $0x0,-0x10(%rbp)
je     11db <item_read+0x4b>
cmpq   $0x0,-0x18(%rbp)
jne    11ee <item_read+0x5e>
movl   $0xffffffff,-0x24(%rbp)
lea    0xe17(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1220 <item_read+0x90>
movl   $0xfffffffe,-0x24(%rbp)
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
jmp    1225 <item_read+0x95>
mov    -0x30(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1243 <item_read+0xb3>
jmp    13a6 <item_read+0x216>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
lea    -0x830(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
lea    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x838(%rbp)
cmpq   $0x0,-0x838(%rbp)
jne    1295 <item_read+0x105>
jmp    1225 <item_read+0x95>
lea    -0x830(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x838(%rbp)
cmpq   $0x0,-0x838(%rbp)
jne    12c0 <item_read+0x130>
jmp    1225 <item_read+0x95>
jmp    12c5 <item_read+0x135>
mov    -0x838(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x838(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
jne    12ec <item_read+0x15c>
jmp    12c5 <item_read+0x135>
mov    -0x838(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1312 <item_read+0x182>
jmp    13ab <item_read+0x21b>
jmp    1317 <item_read+0x187>
mov    -0x838(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x841(%rbp)
je     1348 <item_read+0x1b8>
mov    -0x838(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x841(%rbp)
mov    -0x841(%rbp),%al
test   $0x1,%al
jne    135b <item_read+0x1cb>
jmp    1372 <item_read+0x1e2>
mov    -0x838(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x838(%rbp)
jmp    1317 <item_read+0x187>
mov    -0x838(%rbp),%rax
mov    -0x840(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x840(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1090 <memcpy@plt>
jmp    1225 <item_read+0x95>
jmp    13ab <item_read+0x21b>
cmpq   $0x0,-0x30(%rbp)
je     13bf <item_read+0x22f>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<item_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
test   %rdi,%rdi
je     11bf <item_read+0x2f>
test   %r13,%r13
je     11bf <item_read+0x2f>
xor    %r12d,%r12d
test   %r15,%r15
jne    11d1 <item_read+0x41>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r12d
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11fa <item_read+0x6a>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%r12d
mov    %rbp,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1228 <item_read+0x98>
test   %rbp,%rbp
je     1213 <item_read+0x83>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
jmp    1244 <item_read+0xb4>
mov    %edx,(%r14)
mov    %r15,%rdi
call   1090 <memcpy@plt>
mov    %rbp,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1206 <item_read+0x76>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1238 <item_read+0xa8>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1238 <item_read+0xa8>
mov    %rax,%rsi
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rsi),%ecx
add    $0x1,%rsi
add    $0x1,%rax
cmp    $0x20,%cl
je     1290 <item_read+0x100>
cmp    $0xa,%cl
je     1206 <item_read+0x76>
xor    %edx,%edx
cmp    $0xa,%cl
je     122d <item_read+0x9d>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x20,%cl
je     122d <item_read+0x9d>
movzbl 0x1(%rsi,%rdx,1),%ecx
add    $0x1,%rdx
cmp    $0xa,%cl
jne    12c0 <item_read+0x130>
jmp    122d <item_read+0x9d>

LLVM IR (-O0):
@.str = [30 x i8] c"item_read error, param error\0A\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @item_read(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 i32*
%11 = alloca [2048 x i8]
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i32 0, i32* %9
store i32* null, i32** %10
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %16, %4
store i32 -1, i32* %9
%23 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
store i32 -2, i32* %9
%30 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
br label %32
32: ; preds = %86, %54, %48, %31
%33 = load i32*, i32** %10
%34 = call i32 @feof(i32* %33)
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %99
37: ; preds = %32
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 2048)
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%41 = load i32*, i32** %10
%42 = call i32 @fgets(i8* %40, i32 2048, i32* %41)
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%44 = load i8*, i8** %6
%45 = call i8* @strstr(i8* %43, i8* %44)
store i8* %45, i8** %12
%46 = load i8*, i8** %12
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %49
48: ; preds = %37
br label %32
49: ; preds = %37
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%51 = call i8* @strchr(i8* %50, i8 signext 61)
store i8* %51, i8** %12
%52 = load i8*, i8** %12
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %55
54: ; preds = %49
br label %32
55: ; preds = %49
br label %56
56: ; preds = %62, %55
%57 = load i8*, i8** %12
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %12
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 32
br i1 %61, label %62, label %63
62: ; preds = %56
br label %56
63: ; preds = %56
%64 = load i8*, i8** %12
store i8* %64, i8** %13
%65 = load i8*, i8** %13
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 10
br i1 %68, label %69, label %70
69: ; preds = %63
br label %100
70: ; preds = %63
br label %71
71: ; preds = %83, %70
%72 = load i8*, i8** %12
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 32
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = load i8*, i8** %12
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 10
br label %81
81: ; preds = %76, %71
%82 = phi i1 [ false, %71 ], [ %80, %76 ]
br i1 %82, label %83, label %86
83: ; preds = %81
%84 = load i8*, i8** %12
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %12
br label %71
86: ; preds = %81
%87 = load i8*, i8** %12
%88 = load i8*, i8** %13
%89 = ptrtoint i8* %87 to i64
%90 = ptrtoint i8* %88 to i64
%91 = sub i64 %89, %90
%92 = trunc i64 %91 to i32
%93 = load i32*, i32** %8
store i32 %92, i32* %93
%94 = load i8*, i8** %7
%95 = load i8*, i8** %13
%96 = load i32*, i32** %8
%97 = load i32, i32* %96
%98 = call i32 @memcpy(i8* %94, i8* %95, i32 %97)
br label %32
99: ; preds = %32
br label %100
100: ; preds = %99, %69
%101 = load i32*, i32** %10
%102 = icmp ne i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32*, i32** %10
%105 = call i32 @fclose(i32* %104)
br label %106
106: ; preds = %103, %100
%107 = load i32, i32* %9
ret i32 %107
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@str.2 = [29 x i8] c"item_read error, param error\00"
define i32 @item_read(i8* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
%10 = icmp eq i8* %2, null
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.2, i64 0, i64 0))
br label %14
14: ; preds = %4, %12
%15 = phi i32 [ -1, %12 ], [ 0, %4 ]
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = phi i32 [ -2, %18 ], [ %15, %14 ]
%22 = call i32 @feof(i32* %16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %51
24: ; preds = %20, %48
%25 = call i32 @memset(i8* %6, i32 0, i32 2048)
%26 = call i32 @fgets(i8* %6, i32 2048, i32* %16)
%27 = call i8* @strstr(i8* %6, i8* dereferenceable(1) %1)
%28 = icmp eq i8* %27, null
br i1 %28, label %48, label %29
29: ; preds = %24
%30 = call i8* @strchr(i8* %6, i8 signext 61)
%31 = icmp eq i8* %30, null
br i1 %31, label %48, label %32
32: ; preds = %29, %32
%33 = phi i8* [ %34, %32 ], [ %30, %29 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
switch i8 %35, label %36 [
i8 32, label %32
i8 10, label %51
]
36: ; preds = %32, %39
%37 = phi i8 [ %41, %39 ], [ %35, %32 ]
%38 = phi i8* [ %40, %39 ], [ %34, %32 ]
switch i8 %37, label %39 [
i8 32, label %42
i8 10, label %42
]
39: ; preds = %36
%40 = getelementptr inbounds i8, i8* %38, i64 1
%41 = load i8, i8* %40
br label %36
42: ; preds = %36, %36
%43 = ptrtoint i8* %38 to i64
%44 = ptrtoint i8* %34 to i64
%45 = sub i64 %43, %44
%46 = trunc i64 %45 to i32
store i32 %46, i32* %3
%47 = call i32 @memcpy(i8* %2, i8* %34, i32 %46)
br label %48
48: ; preds = %42, %24, %29
%49 = call i32 @feof(i32* %16)
%50 = icmp eq i32 %49, 0
br i1 %50, label %24, label %51
51: ; preds = %48, %32, %20
br i1 %17, label %54, label %52
52: ; preds = %51
%53 = call i32 @fclose(i32* %16)
br label %54
54: ; preds = %52, %51
ret i32 %21
}