#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char me[] = "set_ext4_err_bit";
  unsigned char sb[1024];
  if (argc != 2) {
    fprintf(stderr, "%s: Usage: %s <ext4_block_device>\n", me, me);
    exit(1);
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "%s: Cannot open block device %s\n", me, argv[1]);
    exit(1);
  }
  if (lseek(fd, 1024, SEEK_SET) == -1) {
    fprintf(stderr, "%s: Cannot lseek to superblock to read\n", me);
    exit(1);
  }
  if (read(fd, sb, 1024) != 1024) {
    fprintf(stderr, "%s: Cannot read superblock\n", me);
    exit(1);
  }
  if ((sb[0x38] != 0x53) || (sb[0x38 + 1] != 0xEF)) {
    fprintf(stderr, "%s: invalid superblock magic\n", me);
    exit(1);
  }
  sb[0x3A] |= 0x2;
  if (lseek(fd, 1024, SEEK_SET) == -1) {
    fprintf(stderr, "%s: Cannot lseek to superblock to write\n", me);
    exit(1);
  }
  if (write(fd, sb, 1024) != 1024) {
    fprintf(stderr, "%s: Cannot write superblock\n", me);
    exit(1);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe6b(%rip),%al
mov    %al,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11db <main+0x6b>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    122b <main+0xbb>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    126f <main+0xff>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0x400,%eax
je     12b3 <main+0x143>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movzbl -0x3f8(%rbp),%eax
cmp    $0x53,%eax
jne    12d5 <main+0x165>
movzbl -0x3f7(%rbp),%eax
cmp    $0xef,%eax
je     12fa <main+0x18a>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movzbl -0x3f6(%rbp),%eax
or     $0x2,%eax
mov    %al,-0x3f6(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    134e <main+0x1de>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
cmp    $0x400,%eax
je     1392 <main+0x222>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x428,%rsp
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
cmp    $0x2,%edi
jne    1250 <main+0xe0>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1268 <main+0xf8>
mov    %eax,%ebx
mov    0x2e17(%rip),%r14
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x400,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0x120>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0x400,%eax
jne    12a2 <main+0x132>
cmpb   $0x53,0x58(%rsp)
jne    12b4 <main+0x144>
cmpb   $0xef,0x59(%rsp)
jne    12b4 <main+0x144>
orb    $0x2,0x5a(%rsp)
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x400,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     12c6 <main+0x156>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1030 <write@plt>
cmp    $0x400,%eax
jne    12d8 <main+0x168>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    %rsp,%rcx
mov    %rcx,%rdx
jmp    127f <main+0x10f>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rcx
lea    0xdb8(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
jmp    12e8 <main+0x178>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
jmp    12e8 <main+0x178>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
jmp    12e8 <main+0x178>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
jmp    12e8 <main+0x178>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.me = [17 x i8] c"set_ext4_err_bit\00"
@stderr = global i32 0
@.str = [35 x i8] c"%s: Usage: %s <ext4_block_device>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [33 x i8] c"%s: Cannot open block device %s\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [40 x i8] c"%s: Cannot lseek to superblock to read\0A\00"
@.str.3 = [28 x i8] c"%s: Cannot read superblock\0A\00"
@.str.4 = [30 x i8] c"%s: invalid superblock magic\0A\00"
@.str.5 = [41 x i8] c"%s: Cannot lseek to superblock to write\0A\00"
@.str.6 = [29 x i8] c"%s: Cannot write superblock\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [17 x i8]
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [17 x i8]* %7 to i8*
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %18
%35 = load i32, i32* %6
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @lseek(i32 %35, i32 1024, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
%45 = load i32, i32* %6
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 1024)
%48 = icmp ne i32 %47, 1024
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 56
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp ne i32 %57, 83
br i1 %58, label %64, label %59
59: ; preds = %54
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 57
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %62, 239
br i1 %63, label %64, label %69
64: ; preds = %59, %54
%65 = load i32, i32* @stderr
%66 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %59
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 58
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = or i32 %72, 2
%74 = trunc i32 %73 to i8
store i8 %74, i8* %70
%75 = load i32, i32* %6
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @lseek(i32 %75, i32 1024, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %84
79: ; preds = %69
%80 = load i32, i32* @stderr
%81 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %69
%85 = load i32, i32* %6
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%87 = call i32 @write(i32 %85, i8* %86, i32 1024)
%88 = icmp ne i32 %87, 1024
br i1 %88, label %89, label %94
89: ; preds = %84
%90 = load i32, i32* @stderr
%91 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%92 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %91)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %84
%95 = load i32, i32* %6
%96 = call i32 @close(i32 %95)
ret i32 0
}

LLVM IR (-O2):
@__const.main.me = [17 x i8] c"set_ext4_err_bit\00"
@stderr = global i32 0
@.str = [35 x i8] c"%s: Usage: %s <ext4_block_device>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [33 x i8] c"%s: Cannot open block device %s\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [40 x i8] c"%s: Cannot lseek to superblock to read\0A\00"
@.str.3 = [28 x i8] c"%s: Cannot read superblock\0A\00"
@.str.4 = [30 x i8] c"%s: invalid superblock magic\0A\00"
@.str.5 = [41 x i8] c"%s: Cannot lseek to superblock to write\0A\00"
@.str.6 = [29 x i8] c"%s: Cannot write superblock\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [17 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %5)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %13
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %16, i32 1024, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = call i32 @read(i32 %16, i8* %6, i32 1024)
%33 = icmp eq i32 %32, 1024
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 56
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 83
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 57
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, -17
%45 = select i1 %41, i1 true, i1 %44
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %38
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 58
%52 = load i8, i8* %51
%53 = or i8 %52, 2
store i8 %53, i8* %51
%54 = load i32, i32* @SEEK_SET
%55 = tail call i32 @lseek(i32 %16, i32 1024, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %50
%62 = call i32 @write(i32 %16, i8* %6, i32 1024)
%63 = icmp eq i32 %62, 1024
br i1 %63, label %68, label %64
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %61
%69 = tail call i32 @close(i32 %16)
ret i32 0
}