#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 */
scalar_t__ dump_messages(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ show_usage(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *in;
  char buf[12];
  int err;
  if (argc > 2) {
    show_usage(argv[0]);
    return 1;
  }
  in = (argc == 2) ? fopen(argv[1], "r") : stdin;
  if (in == NULL) {
    perror("Cannot open input file");
    return 1;
  }
  err = (fread(buf, 1, 12, in) != 12 ||
         strncmp(buf, "FBS 001.000\n", 12) != 0 || dump_messages(in) != 0);
  if (in != stdin)
    fclose(in);
  if (!err)
    fprintf(stderr, "Succeeded.\n");
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11b8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <show_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x146>
cmpl   $0x2,-0x8(%rbp)
jne    11df <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    11ed <main+0x6d>
mov    0x2e02(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0x98>
lea    0xdfb(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x146>
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc,%edx
call   1050 <fread@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0xc,%ecx
mov    %al,-0x31(%rbp)
jne    1279 <main+0xf9>
lea    -0x24(%rbp),%rdi
lea    0xdcf(%rip),%rsi
mov    $0xc,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
jne    1279 <main+0xf9>
mov    -0x18(%rbp),%rdi
call   1030 <dump_messages@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d59(%rip),%rcx
cmp    (%rcx),%rax
je     12a1 <main+0x121>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x28(%rbp)
jne    12c0 <main+0x140>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jl     119d <main+0x1d>
mov    (%rsi),%rdi
call   1080 <show_usage@plt>
mov    $0x1,%eax
jmp    1240 <main+0xc0>
cmp    $0x2,%edi
jne    1247 <main+0xc7>
mov    0x8(%rsi),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     125a <main+0xda>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    $0x1,%bpl
cmp    $0xc,%eax
jne    120b <main+0x8b>
lea    0xe31(%rip),%rsi
lea    0xc(%rsp),%rdi
mov    $0xc,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    120b <main+0x8b>
mov    %rbx,%rdi
call   1030 <dump_messages@plt>
test   %rax,%rax
setne  %bpl
mov    0x2dd6(%rip),%rax
cmp    (%rax),%rbx
je     121f <main+0x9f>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0x1,%eax
test   %bpl,%bpl
jne    1240 <main+0xc0>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11c2 <main+0x42>
lea    0xda1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    1240 <main+0xc0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [23 x i8] c"Cannot open input file\00"
@.str.2 = [13 x i8] c"FBS 001.000\0A\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"Succeeded.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [12 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 2
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 @show_usage(i8* %14)
store i32 1, i32* %3
br label %62
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
24: ; preds = %16
%25 = load i32*, i32** @stdin
br label %26
26: ; preds = %24, %19
%27 = phi i32* [ %23, %19 ], [ %25, %24 ]
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %62
32: ; preds = %26
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%34 = load i32*, i32** %6
%35 = call i32 @fread(i8* %33, i32 1, i32 12, i32* %34)
%36 = icmp ne i32 %35, 12
br i1 %36, label %45, label %37
37: ; preds = %32
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%40 = icmp ne i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i32*, i32** %6
%43 = call i64 @dump_messages(i32* %42)
%44 = icmp ne i64 %43, 0
br label %45
45: ; preds = %41, %37, %32
%46 = phi i1 [ true, %37 ], [ true, %32 ], [ %44, %41 ]
%47 = zext i1 %46 to i32
store i32 %47, i32* %8
%48 = load i32*, i32** %6
%49 = load i32*, i32** @stdin
%50 = icmp ne i32* %48, %49
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %45
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %57, %54
%61 = load i32, i32* %8
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %30, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [23 x i8] c"Cannot open input file\00"
@.str.2 = [13 x i8] c"FBS 001.000\0A\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"Succeeded.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @show_usage(i8* %7)
br label %41
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %9
%16 = load i32*, i32** @stdin
br label %17
17: ; preds = %15, %11
%18 = phi i32* [ %14, %11 ], [ %16, %15 ]
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %41
22: ; preds = %17
%23 = call i32 @fread(i8* %4, i32 1, i32 12, i32* %18)
%24 = icmp eq i32 %23, 12
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i64 @dump_messages(i32* %18)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %28, %25, %22
%32 = phi i1 [ true, %25 ], [ true, %22 ], [ %30, %28 ]
%33 = load i32*, i32** @stdin
%34 = icmp eq i32* %18, %33
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 @fclose(i32* %18)
br label %37
37: ; preds = %35, %31
br i1 %32, label %41, label %38
38: ; preds = %37
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %37, %38, %20, %6
%42 = phi i32 [ 1, %6 ], [ 1, %20 ], [ 0, %38 ], [ 1, %37 ]
ret i32 %42
}