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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ syncfs(int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  int run_or_verify = 0;
  if (argc != 3) {
    usage(argv[0]);
  }
  if (!strcmp(argv[1], "run")) {
    run_or_verify = 1;
  } else if (!strcmp(argv[1], "verify")) {
    run_or_verify = 0;
  } else {
    usage(argv[0]);
  }
  if (run_or_verify) {
    fd = open(argv[2], O_WRONLY | O_CREAT);
    if (fd < 0) {
      perror(argv[2]);
      return 1;
    }
    write(fd, "Hello World\n", 12);
    syncfs(fd);
    system("echo c > /proc/sysrq-trigger");
  } else {
    char buf[13];
    fd = open(argv[2], O_RDONLY);
    if (fd < 0) {
      perror(argv[2]);
      return 1;
    }
    memset(buf, 0, sizeof(buf));
    read(fd, buf, 12);
    if (strcmp(buf, "Hello World\n")) {
      fprintf(stderr, "Output does not match: %s\n", buf);
    } else {
      fprintf(stderr, "%s has no corruption\n", argv[2]);
    }
  }
  if (close(fd) < 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e3 <main+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0e(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    120d <main+0x5d>
movl   $0x1,-0x18(%rbp)
jmp    1248 <main+0x98>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde8(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1237 <main+0x87>
movl   $0x0,-0x18(%rbp)
jmp    1243 <main+0x93>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <usage@plt>
jmp    1248 <main+0x98>
cmpl   $0x0,-0x18(%rbp)
je     12c4 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1297 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a0 <main+0x1f0>
mov    -0x14(%rbp),%edi
lea    0xd6a(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <syncfs@plt>
lea    0xd5e(%rip),%rdi
call   1050 <system@plt>
jmp    137b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1300 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a0 <main+0x1f0>
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0xc,%edx
call   1080 <read@plt>
lea    -0x25(%rbp),%rdi
lea    0xcdf(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1359 <main+0x1a9>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    -0x25(%rbp),%rdx
lea    0xce6(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1376 <main+0x1c6>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xcdf(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    137b <main+0x1cb>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jge    1399 <main+0x1e9>
movl   $0x1,-0x4(%rbp)
jmp    13a0 <main+0x1f0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11c8 <main+0x18>
mov    (%rbx),%rdi
call   10b0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe2d(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1268 <main+0xb8>
mov    0x8(%rbx),%rdi
lea    0xe18(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11fe <main+0x4e>
mov    (%rbx),%rdi
call   10b0 <usage@plt>
mov    0x10(%rbx),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
test   %eax,%eax
js     12d5 <main+0x125>
mov    %eax,%ebp
lea    0x3(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <read@plt>
lea    0xdc7(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcmp@plt>
mov    0x2d7d(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
je     12b1 <main+0x101>
lea    0xdd4(%rip),%rsi
lea    0x3(%rsp),%rdx
jmp    12bc <main+0x10c>
mov    0x10(%rbx),%rdi
mov    0x2d4d(%rip),%rax
mov    0x2d7e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10c0 <open@plt>
test   %eax,%eax
js     12d5 <main+0x125>
mov    %eax,%ebp
lea    0xd7b(%rip),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <syncfs@plt>
lea    0xd6e(%rip),%rdi
call   1050 <system@plt>
jmp    12c1 <main+0x111>
mov    0x10(%rbx),%rdx
lea    0xd94(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
shr    $0x3f,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x10(%rbx),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
jmp    12cc <main+0x11c>

LLVM IR (-O0):
@.str = [4 x i8] c"run\00"
@.str.1 = [7 x i8] c"verify\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [13 x i8] c"Hello World\0A\00"
@.str.3 = [29 x i8] c"echo c > /proc/sysrq-trigger\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [27 x i8] c"Output does not match: %s\0A\00"
@.str.5 = [22 x i8] c"%s has no corruption\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [13 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
br label %16
16: ; preds = %11, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 1, i32* %7
br label %36
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %23
store i32 0, i32* %7
br label %35
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @usage(i8* %33)
br label %35
35: ; preds = %30, %29
br label %36
36: ; preds = %35, %22
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32, i32* @O_WRONLY
%44 = load i32, i32* @O_CREAT
%45 = or i32 %43, %44
%46 = call i32 @open(i8* %42, i32 %45)
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %39
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @perror(i8* %52)
store i32 1, i32* %3
br label %99
54: ; preds = %39
%55 = load i32, i32* %6
%56 = call i32 @write(i32 %55, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%57 = load i32, i32* %6
%58 = call i32 @syncfs(i32 %57)
%59 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %93
60: ; preds = %36
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = load i32, i32* @O_RDONLY
%65 = call i32 @open(i8* %63, i32 %64)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %60
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
%72 = call i32 @perror(i8* %71)
store i32 1, i32* %3
br label %99
73: ; preds = %60
%74 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i32 0, i32 13)
%76 = load i32, i32* %6
%77 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 12)
%79 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%80 = call i64 @strcmp(i8* %79, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %73
%83 = load i32, i32* @stderr
%84 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %84)
br label %92
86: ; preds = %73
%87 = load i32, i32* @stderr
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 2
%90 = load i8*, i8** %89
%91 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %86, %82
br label %93
93: ; preds = %92, %54
%94 = load i32, i32* %6
%95 = call i64 @close(i32 %94)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %93
store i32 1, i32* %3
br label %99
98: ; preds = %93
store i32 0, i32* %3
br label %99
99: ; preds = %98, %97, %68, %49
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [4 x i8] c"run\00"
@.str.1 = [7 x i8] c"verify\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [13 x i8] c"Hello World\0A\00"
@.str.3 = [29 x i8] c"echo c > /proc/sysrq-trigger\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [27 x i8] c"Output does not match: %s\0A\00"
@.str.5 = [22 x i8] c"%s has no corruption\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [13 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6)
br label %8
8: ; preds = %5, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %13
%18 = load i8*, i8** %1
%19 = tail call i32 @usage(i8* %18)
br label %35
20: ; preds = %8
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = tail call i32 @open(i8* %22, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i8*, i8** %21
%30 = tail call i32 @perror(i8* %29)
br label %62
31: ; preds = %20
%32 = tail call i32 @write(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%33 = tail call i32 @syncfs(i32 %26)
%34 = tail call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %57
35: ; preds = %13, %17
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds i8*, i8** %1, i64 2
%38 = load i8*, i8** %37
%39 = load i32, i32* @O_RDONLY
%40 = tail call i32 @open(i8* %38, i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %54, label %42
42: ; preds = %35
%43 = call i32 @memset(i8* %36, i32 0, i32 13)
%44 = call i32 @read(i32 %40, i8* %36, i32 12)
%45 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
%47 = load i32, i32* @stderr
br i1 %46, label %50, label %48
48: ; preds = %42
%49 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %53
50: ; preds = %42
%51 = load i8*, i8** %37
%52 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %48, %50
br label %57
54: ; preds = %35
%55 = load i8*, i8** %37
%56 = tail call i32 @perror(i8* %55)
br label %62
57: ; preds = %53, %31
%58 = phi i32 [ %26, %31 ], [ %40, %53 ]
%59 = call i64 @close(i32 %58)
%60 = lshr i64 %59, 63
%61 = trunc i64 %60 to i32
br label %62
62: ; preds = %54, %57, %28
%63 = phi i32 [ 1, %28 ], [ 1, %54 ], [ %61, %57 ]
ret i32 %63
}