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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int main(void) {
  FILE *fp = NULL;
  char flag[16];
  size_t size;
  int cnt = 0;
  fp = fopen("/dev/mtdblock8", "rb+");
  if (fp == NULL) {
    fprintf(stderr, "fopen /dev/mtdblock8 error!!!");
    syslog(LOG_ERR, "fopen /dev/mtdblock8 error!!!");
    return -1;
  }
  while (cnt < (5)) {
    cnt++;
    fseek(fp, 0L, SEEK_SET);
    memset(flag, 0xFF, sizeof(flag));
    size = fwrite(flag, 1, 16, fp);
    if (size == 16) {
      break;
    }
  }
  fclose(fp);
  if (cnt == (5)) {
    fprintf(stderr, "fwrite /dev/mtdblock8 error!!!");
    syslog(LOG_ERR, "fwrite /dev/mtdblock8 error!!!");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe6b(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e6 <main+0x76>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x137>
jmp    11eb <main+0x7b>
cmpl   $0x5,-0x2c(%rbp)
jge    1257 <main+0xe7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    $0xff,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1090 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x10,-0x28(%rbp)
jne    1252 <main+0xe2>
jmp    1257 <main+0xe7>
jmp    11eb <main+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x5,-0x2c(%rbp)
jne    12a0 <main+0x130>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x137>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1215 <main+0xa5>
mov    %rax,%r12
xor    %ebx,%ebx
mov    0x2e34(%rip),%r15
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%ebp
mov    (%r15),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
cmp    $0x10,%rax
je     11f4 <main+0x84>
cmp    $0x4,%ebx
mov    %ebp,%ebx
jb     11b0 <main+0x40>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmp    $0x5,%ebp
jne    1243 <main+0xd3>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rbx
jmp    1225 <main+0xb5>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rbx
mov    %rbx,%rsi
call   1050 <fprintf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1060 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/mtdblock8\00"
@.str.1 = [4 x i8] c"rb+\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"fopen /dev/mtdblock8 error!!!\00"
@LOG_ERR = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [31 x i8] c"fwrite /dev/mtdblock8 error!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [16 x i8]
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %5
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @LOG_ERR
%13 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
14: ; preds = %0
br label %15
15: ; preds = %32, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
%21 = load i32*, i32** %2
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i64 0, i32 %22)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 255, i32 16)
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%27 = load i32*, i32** %2
%28 = call i64 @fwrite(i8* %26, i32 1, i32 16, i32* %27)
store i64 %28, i64* %4
%29 = load i64, i64* %4
%30 = icmp eq i64 %29, 16
br i1 %30, label %31, label %32
31: ; preds = %18
br label %33
32: ; preds = %18
br label %15
33: ; preds = %31, %15
%34 = load i32*, i32** %2
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 5
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @LOG_ERR
%42 = call i32 @syslog(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
43: ; preds = %33
store i32 0, i32* %1
br label %44
44: ; preds = %43, %38, %9
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/mtdblock8\00"
@.str.1 = [4 x i8] c"rb+\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"fopen /dev/mtdblock8 error!!!\00"
@LOG_ERR = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [31 x i8] c"fwrite /dev/mtdblock8 error!!!\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @LOG_ERR
%9 = tail call i32 @syslog(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %28
10: ; preds = %0, %10
%11 = phi i32 [ %12, %10 ], [ 0, %0 ]
%12 = add nuw nsw i32 %11, 1
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %3, i64 0, i32 %13)
%15 = call i32 @memset(i8* %2, i32 255, i32 16)
%16 = call i64 @fwrite(i8* %2, i32 1, i32 16, i32* %3)
%17 = icmp ne i64 %16, 16
%18 = icmp ult i32 %11, 4
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %10, label %20
20: ; preds = %10
%21 = call i32 @fclose(i32* %3)
%22 = icmp eq i32 %12, 5
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @LOG_ERR
%27 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %20, %23, %5
%29 = phi i32 [ -1, %5 ], [ -1, %23 ], [ 0, %20 ]
ret i32 %29
}