#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*/ _IO(float, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int fd, err;
  if (argc != 2) {
    printf("usage: ext4-swap-boot-inode FILE-TO-SWAP\n");
    return 1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    perror("open");
    return 1;
  }
  err = ioctl(fd, _IO('f', 17));
  if (err < 0) {
    perror("ioctl");
    return 1;
  }
  close(fd);
  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)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d3 <main+0x73>
lea    0xe6c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movss  0xe1f(%rip),%xmm0
mov    $0x11,%edi
call   1040 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    121a <main+0xba>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <main+0xc9>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11a8 <main+0x48>
mov    0x8(%rsi),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11bb <main+0x5b>
mov    %eax,%ebx
movss  0xe7a(%rip),%xmm0
mov    $0x11,%edi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %eax,%eax
js     11c4 <main+0x64>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe42(%rip),%rdi
jmp    11cb <main+0x6b>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
jmp    11b4 <main+0x54>

LLVM IR (-O0):
@.str = [42 x i8] c"usage: ext4-swap-boot-inode FILE-TO-SWAP\0A\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"ioctl\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
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %33
22: ; preds = %12
%23 = load i32, i32* %6
%24 = call i32 @_IO(float 1.020000e+02, i32 17)
%25 = call i32 @ioctl(i32 %23, i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %33
30: ; preds = %22
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %28, %20, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"ioctl\00"
@str = [41 x i8] c"usage: ext4-swap-boot-inode FILE-TO-SWAP\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
14: ; preds = %6
%15 = tail call i32 @_IO(float 1.020000e+02, i32 17)
%16 = tail call i32 @ioctl(i32 %10, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %14
%21 = tail call i32 @close(i32 %10)
br label %22
22: ; preds = %20, %18, %12, %4
%23 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %18 ], [ 0, %20 ]
ret i32 %23
}