#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int strlen(char *);
int /*<<< orphan*/ write_mtd(unsigned char *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/, int);
clear_cfg_flag() {
  FILE *fp_mtd;
  unsigned char clean_flag[strlen("airdisk")];
  memset(clean_flag, 0xff, strlen("airdisk"));
  fp_mtd = fopen("/dev/mtdblock2", "rb+");
  if (fp_mtd == NULL) {
    exit(1);
  }
  write_mtd(clean_flag, fp_mtd, 0, strlen("airdisk"));
  fclose(fp_mtd);
}


x86 assembly (clang, -O0):
<clear_cfg_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
mov    $0xff,%esi
call   1050 <memset@plt>
lea    0xe4c(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <clear_cfg_flag+0x81>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe10(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
xor    %edx,%edx
call   1080 <write_mtd@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_cfg_flag>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
lea    0xe92(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %eax,%edx
call   1050 <memset@plt>
lea    0xe61(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e7 <clear_cfg_flag+0x87>
mov    %rax,%r14
lea    0xe3e(%rip),%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %eax,%ecx
call   1080 <write_mtd@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"airdisk\00"
@.str.1 = [15 x i8] c"/dev/mtdblock2\00"
@.str.2 = [4 x i8] c"rb+\00"
define i32 @clear_cfg_flag() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %3
%8 = alloca i8, i64 %6
store i64 %6, i64* %4
%9 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @memset(i8* %8, i32 255, i32 %9)
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32*, i32** %2
%18 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @write_mtd(i8* %8, i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %2
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %3
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [8 x i8] c"airdisk\00"
@.str.1 = [15 x i8] c"/dev/mtdblock2\00"
@.str.2 = [4 x i8] c"rb+\00"
define i32 @clear_cfg_flag() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @memset(i8* %3, i32 255, i32 %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @write_mtd(i8* %3, i32* %6, i32 0, i32 %11)
%13 = call i32 @fclose(i32* %6)
ret i32 undef
}