#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 check_resume_block(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ clear_resume_block(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int print_usage(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *dev = NULL;
  int rc;
  if (argc != 2)
    return print_usage(stderr, 1);
  if (!strcmp(argv[1], "--help")) {
    return print_usage(stdout, 0);
  }
  if (!(dev = fopen(argv[1], "r+b"))) {
    fprintf(stderr, "Could not open \"%s\": %m\n", argv[1]);
    return 1;
  }
  rc = check_resume_block(dev, 0);
  if (rc < 0) {
    fprintf(stderr, "Could not check \"%s\" for swap signature: %m\n", argv[1]);
    fclose(dev);
    return 2;
  }
  if (rc == 1) {
    if (clear_resume_block(dev, 0)) {
      fprintf(stderr, "Could not clear swap signature on \"%s\": %m\n",
              argv[1]);
      fclose(dev);
      return 1;
    }
  }
  fclose(dev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1080 <print_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12e3 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <main+0x78>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1080 <print_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12e3 <main+0x173>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe10(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1233 <main+0xc3>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e3 <main+0x173>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1090 <check_resume_block@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    127d <main+0x10d>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e3 <main+0x173>
cmpl   $0x1,-0x1c(%rbp)
jne    12d3 <main+0x163>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <clear_resume_block@plt>
cmp    $0x0,%rax
je     12ce <main+0x15e>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e3 <main+0x173>
jmp    12d3 <main+0x163>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11f9 <main+0x89>
mov    %rsi,%r15
mov    0x8(%rsi),%rbx
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1209 <main+0x99>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     121e <main+0xae>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <check_resume_block@plt>
test   %eax,%eax
js     124a <main+0xda>
cmp    $0x1,%eax
jne    123e <main+0xce>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <clear_resume_block@plt>
test   %rax,%rax
je     123e <main+0xce>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xe6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    1270 <main+0x100>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
jmp    1214 <main+0xa4>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <print_usage@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdd9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1270 <main+0x100>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1270 <main+0x100>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdc6(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [25 x i8] c"Could not open \22%s\22: %m\0A\00"
@.str.3 = [45 x i8] c"Could not check \22%s\22 for swap signature: %m\0A\00"
@.str.4 = [44 x i8] c"Could not clear swap signature on \22%s\22: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @print_usage(i32 %11, i32 1)
store i32 %12, i32* %3
br label %66
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i32, i32* @stdout
%21 = call i32 @print_usage(i32 %20, i32 0)
store i32 %21, i32* %3
br label %66
22: ; preds = %13
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %34, label %28
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %66
34: ; preds = %22
%35 = load i32*, i32** %6
%36 = call i32 @check_resume_block(i32* %35, i32 0)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
store i32 2, i32* %3
br label %66
47: ; preds = %34
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load i32*, i32** %6
%52 = call i64 @clear_resume_block(i32* %51, i32 0)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
store i32 1, i32* %3
br label %66
62: ; preds = %50
br label %63
63: ; preds = %62, %47
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %3
br label %66
66: ; preds = %63, %54, %39, %28, %19, %10
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [25 x i8] c"Could not open \22%s\22: %m\0A\00"
@.str.3 = [45 x i8] c"Could not check \22%s\22 for swap signature: %m\0A\00"
@.str.4 = [44 x i8] c"Could not clear swap signature on \22%s\22: %m\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @print_usage(i32 %5, i32 1)
br label %42
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @stdout
%14 = tail call i32 @print_usage(i32 %13, i32 0)
br label %42
15: ; preds = %7
%16 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %8
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %42
22: ; preds = %15
%23 = tail call i32 @check_resume_block(i32* %16, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %8
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = tail call i32 @fclose(i32* %16)
br label %42
30: ; preds = %22
%31 = icmp eq i32 %23, 1
br i1 %31, label %32, label %40
32: ; preds = %30
%33 = tail call i64 @clear_resume_block(i32* %16, i32 0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %8
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = tail call i32 @fclose(i32* %16)
br label %42
40: ; preds = %32, %30
%41 = tail call i32 @fclose(i32* %16)
br label %42
42: ; preds = %40, %35, %25, %18, %12, %4
%43 = phi i32 [ %6, %4 ], [ 2, %25 ], [ 1, %35 ], [ 0, %40 ], [ 1, %18 ], [ %14, %12 ]
ret i32 %43
}