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


x86 assembly (clang, -O0):
<set_cfg_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <set_cfg_flag+0x34>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe80(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%ecx
lea    0xe6e(%rip),%rdi
xor    %edx,%edx
call   1070 <write_mtd@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_cfg_flag>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119c <set_cfg_flag+0x4c>
mov    %rax,%rbx
lea    0xe9d(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %eax,%ecx
call   1070 <write_mtd@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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