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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_mtd(unsigned char *, int /*<<< orphan*/ *,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int check_cfg_flag(int ifprint) {
  unsigned char cfg_flag[16];
  FILE *fp_mtd;
  fp_mtd = fopen("/dev/mtdblock2", "rb");
  if (fp_mtd == NULL) {
    exit(1);
  }
  memset(cfg_flag, 0, sizeof(cfg_flag));
  read_mtd(cfg_flag, fp_mtd, 0, strlen("airdisk"));
  fclose(fp_mtd);
  if (!strcmp((char *)cfg_flag, "airdisk")) {
    if (ifprint != 1)
      printf("airdisk");
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<check_cfg_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe6e(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b7 <check_cfg_flag+0x37>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe34(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
xor    %edx,%edx
call   1080 <read_mtd@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x20(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1238 <check_cfg_flag+0xb8>
cmpl   $0x1,-0x8(%rbp)
je     122c <check_cfg_flag+0xac>
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <check_cfg_flag+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_cfg_flag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
lea    0xe7c(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1206 <check_cfg_flag+0x96>
mov    %rax,%rbx
mov    %rsp,%rbp
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe5e(%rip),%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %eax,%ecx
call   1070 <read_mtd@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movabs $0x6b736964726961,%rax
cmp    %rax,(%rsp)
jne    11f8 <check_cfg_flag+0x88>
mov    $0x1,%r15d
cmp    $0x1,%r14d
je     11f8 <check_cfg_flag+0x88>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/mtdblock2\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"airdisk\00"
define i32 @check_cfg_flag(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca i32*
store i32 %0, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 16)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @read_mtd(i8* %14, i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %5
%19 = call i32 @fclose(i32* %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %11
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
store i32 1, i32* %2
br label %30
29: ; preds = %11
store i32 0, i32* %2
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/mtdblock2\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [8 x i8] c"airdisk\00"
define i32 @check_cfg_flag(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = call i32 @memset(i8* %3, i32 0, i32 16)
%10 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @read_mtd(i8* %3, i32* %4, i32 0, i32 %10)
%12 = call i32 @fclose(i32* %4)
%13 = bitcast [16 x i8]* %2 to i64*
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 30244719002020193
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = icmp eq i32 %0, 1
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %8, %16, %18
%21 = phi i32 [ 1, %18 ], [ 1, %16 ], [ 0, %8 ]
ret i32 %21
}