#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);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned char buf[512];
  FILE *f;
  if (argc != 2) {
    fprintf(stderr, "%s: hdffile\n", argv[0]);
    exit(1);
  }
  f = fopen(argv[1], "r+");
  if (f == NULL) {
    perror(argv[1]);
    exit(1);
  }
  if (fread(buf, 512, 1, f) != 1) {
    fprintf(stderr, "%s: short read.\n", argv[1]);
    exit(1);
  }
  if (memcmp(buf, "RS-IDE", 6)) {
    fprintf(stderr, "%s: not an HDF image.\n", argv[1]);
    exit(1);
  }
  buf[0x16 + 99] |= 2;
  rewind(f);
  if (fwrite(buf, 512, 1, f) != 1) {
    fprintf(stderr, "%s: short write.\n", argv[1]);
    exit(1);
  }
  if (fclose(f)) {
    perror(argv[1]);
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d9 <main+0x49>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe25(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    1219 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1266 <main+0xd6>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb9(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x6,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     12af <main+0x11f>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd88(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movzbl -0x197(%rbp),%eax
or     $0x2,%eax
mov    %al,-0x197(%rbp)
mov    -0x218(%rbp),%rdi
call   1050 <rewind@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
je     1318 <main+0x188>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd36(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x218(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1345 <main+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ca <main+0x3a>
mov    0x8(%rbx),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    11ec <main+0x5c>
mov    0x8(%rbx),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe23(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1261 <main+0xd1>
lea    0xe11(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    127a <main+0xea>
orb    $0x2,0x79(%rsp)
mov    %r14,%rdi
call   1050 <rewind@plt>
mov    %rsp,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
jne    1293 <main+0x103>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    11b7 <main+0x27>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd9b(%rip),%rsi
jmp    11dd <main+0x4d>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd9a(%rip),%rsi
jmp    11dd <main+0x4d>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd98(%rip),%rsi
jmp    11dd <main+0x4d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"%s: hdffile\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [17 x i8] c"%s: short read.\0A\00"
@.str.3 = [7 x i8] c"RS-IDE\00"
@.str.4 = [23 x i8] c"%s: not an HDF image.\0A\00"
@.str.5 = [18 x i8] c"%s: short write.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @perror(i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %7
%33 = call i32 @fread(i8* %31, i32 512, i32 1, i32* %32)
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%44 = call i64 @memcmp(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 121
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = or i32 %56, 2
%58 = trunc i32 %57 to i8
store i8 %58, i8* %54
%59 = load i32*, i32** %7
%60 = call i32 @rewind(i32* %59)
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%62 = load i32*, i32** %7
%63 = call i32 @fwrite(i8* %61, i32 512, i32 1, i32* %62)
%64 = icmp ne i32 %63, 1
br i1 %64, label %65, label %72
65: ; preds = %53
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %53
%73 = load i32*, i32** %7
%74 = call i64 @fclose(i32* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = call i32 @perror(i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %72
%83 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"%s: hdffile\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [17 x i8] c"%s: short read.\0A\00"
@.str.3 = [7 x i8] c"RS-IDE\00"
@.str.4 = [23 x i8] c"%s: not an HDF image.\0A\00"
@.str.5 = [18 x i8] c"%s: short write.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i32 @perror(i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = call i32 @fread(i8* %4, i32 512, i32 1, i32* %14)
%22 = icmp eq i32 %21, 1
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %12
%26 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%30 = icmp eq i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %12
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 121
%38 = load i8, i8* %37
%39 = or i8 %38, 2
store i8 %39, i8* %37
%40 = call i32 @rewind(i32* %14)
%41 = call i32 @fwrite(i8* %4, i32 512, i32 1, i32* %14)
%42 = icmp eq i32 %41, 1
br i1 %42, label %48, label %43
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %12
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %36
%49 = call i64 @fclose(i32* %14)
%50 = icmp eq i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i8*, i8** %12
%53 = call i32 @perror(i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = call i32 @exit(i32 0)
unreachable
}