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

/* Variables and functions */
int /*<<< orphan*/ clear_crlf(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *, char *,
                            char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_uci_opt_value(char *filename, char *section, char *option, char *value,
                      int val_len) {
  FILE *fp = NULL;
  char cmd[256] = {0};
  char buf[128] = {0};
  if (!filename || !section || !option || !value) {
    printf("get uci opt v: arg error.");
    return 1;
  }
  snprintf(cmd, sizeof(cmd),
           "uci get %s.%s.%s >/dev/null 2>&1 "
           "&& uci get %s.%s.%s",
           filename, section, option, filename, section, option);
  fp = popen(cmd, "r");
  if (NULL != fp) {
    fgets(buf, sizeof(buf), fp);
    clear_crlf(buf);
    pclose(fp);
    fp = NULL;
    printf("get uci %s.%s.%s=%s.", filename, section, option, buf);
    strncpy(value, buf, val_len < sizeof(buf) ? val_len : sizeof(buf));
  } else {
    printf("read uci error.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_uci_opt_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x1c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11f9 <get_uci_opt_value+0x79>
cmpq   $0x0,-0x18(%rbp)
je     11f9 <get_uci_opt_value+0x79>
cmpq   $0x0,-0x20(%rbp)
je     11f9 <get_uci_opt_value+0x79>
cmpq   $0x0,-0x28(%rbp)
jne    1213 <get_uci_opt_value+0x93>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1347 <get_uci_opt_value+0x1c7>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x10(%rbp),%r11
mov    -0x18(%rbp),%r10
mov    -0x20(%rbp),%rax
mov    $0x100,%esi
lea    0xddc(%rip),%rdx
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <snprintf@plt>
lea    -0x140(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
je     1332 <get_uci_opt_value+0x1b2>
lea    -0x1c0(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
lea    -0x1c0(%rbp),%rdi
call   10a0 <clear_crlf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <pclose@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x1c0(%rbp),%r8
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x1d0(%rbp)
lea    -0x1c0(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
movslq -0x2c(%rbp),%rax
cmp    $0x80,%rax
jae    1300 <get_uci_opt_value+0x180>
movslq -0x2c(%rbp),%rax
mov    %rax,-0x1d8(%rbp)
jmp    1311 <get_uci_opt_value+0x191>
mov    $0x80,%eax
mov    %rax,-0x1d8(%rbp)
jmp    1311 <get_uci_opt_value+0x191>
mov    -0x1c8(%rbp),%rsi
mov    -0x1d0(%rbp),%rdi
mov    -0x1d8(%rbp),%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    1340 <get_uci_opt_value+0x1c0>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uci_opt_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
test   %rdi,%rdi
je     131f <get_uci_opt_value+0x1af>
mov    %rsi,%r13
test   %rsi,%rsi
je     131f <get_uci_opt_value+0x1af>
mov    %rdx,%r12
test   %rdx,%rdx
je     131f <get_uci_opt_value+0x1af>
mov    %rcx,%r15
test   %rcx,%rcx
je     131f <get_uci_opt_value+0x1af>
mov    %r8d,%r14d
mov    %rdi,%rbp
sub    $0x8,%rsp
lea    0xdad(%rip),%rdx
lea    0x98(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rcx
mov    %r13,%r8
mov    %r12,%r9
push   %r12
push   %r13
push   %rbp
call   1060 <snprintf@plt>
add    $0x20,%rsp
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1334 <get_uci_opt_value+0x1c4>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    %r15,0x8(%rsp)
mov    %r14d,%r15d
mov    $0x80,%r14d
mov    $0x80,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
lea    0x10(%rsp),%rdi
call   1090 <clear_crlf@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
lea    0xd69(%rip),%rdi
xor    %ebx,%ebx
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
lea    0x10(%rsp),%rbp
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x80,%r15d
cmovb  %r15d,%r14d
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
jmp    1344 <get_uci_opt_value+0x1d4>
lea    0xcda(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    1344 <get_uci_opt_value+0x1d4>
lea    0xd2b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"get uci opt v: arg error.\00"
@.str.1 = [53 x i8] c"uci get %s.%s.%s >/dev/null 2>&1 && uci get %s.%s.%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"get uci %s.%s.%s=%s.\00"
@.str.4 = [16 x i8] c"read uci error.\00"
define i32 @get_uci_opt_value(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca [256 x i8]
%14 = alloca [128 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32* null, i32** %12
%15 = bitcast [256 x i8]* %13 to i8*
%16 = bitcast [128 x i8]* %14 to i8*
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %5
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %10
%27 = icmp ne i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %25, %22, %19, %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %72
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call i32 @snprintf(i8* %31, i32 256, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33, i8* %34, i8* %35, i8* %36, i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%40 = call i32* @popen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %40, i32** %12
%41 = load i32*, i32** %12
%42 = icmp ne i32* null, %41
br i1 %42, label %43, label %69
43: ; preds = %30
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%45 = load i32*, i32** %12
%46 = call i32 @fgets(i8* %44, i32 128, i32* %45)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%48 = call i32 @clear_crlf(i8* %47)
%49 = load i32*, i32** %12
%50 = call i32 @pclose(i32* %49)
store i32* null, i32** %12
%51 = load i8*, i8** %7
%52 = load i8*, i8** %8
%53 = load i8*, i8** %9
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52, i8* %53, i8* %54)
%56 = load i8*, i8** %10
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = icmp ult i64 %59, 128
br i1 %60, label %61, label %64
61: ; preds = %43
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
br label %65
64: ; preds = %43
br label %65
65: ; preds = %64, %61
%66 = phi i64 [ %63, %61 ], [ 128, %64 ]
%67 = trunc i64 %66 to i32
%68 = call i32 @strncpy(i8* %56, i8* %57, i32 %67)
br label %71
69: ; preds = %30
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %69, %65
store i32 0, i32* %6
br label %72
72: ; preds = %71, %28
%73 = load i32, i32* %6
ret i32 %73
}

LLVM IR (-O2):
@.str = [26 x i8] c"get uci opt v: arg error.\00"
@.str.1 = [53 x i8] c"uci get %s.%s.%s >/dev/null 2>&1 && uci get %s.%s.%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"get uci %s.%s.%s=%s.\00"
@.str.4 = [16 x i8] c"read uci error.\00"
define i32 @get_uci_opt_value(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = alloca [128 x i8]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%10 = icmp ne i8* %0, null
%11 = icmp ne i8* %1, null
%12 = and i1 %10, %11
%13 = icmp ne i8* %2, null
%14 = and i1 %12, %13
%15 = icmp ne i8* %3, null
%16 = and i1 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %33
19: ; preds = %5
%20 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i8* %0, i8* %1, i8* %2)
%21 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = call i32 @fgets(i8* %9, i32 128, i32* %21)
%25 = call i32 @clear_crlf(i8* %9)
%26 = call i32 @pclose(i32* %21)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i8* %9)
%28 = icmp ult i32 %4, 128
%29 = select i1 %28, i32 %4, i32 128
%30 = call i32 @strncpy(i8* %3, i8* %9, i32 %29)
br label %33
31: ; preds = %19
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %23, %31, %17
%34 = phi i32 [ 1, %17 ], [ 0, %31 ], [ 0, %23 ]
ret i32 %34
}