#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_RDONLY;
int /*<<< orphan*/ close(int);
int ioctl(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int rd_fd = open("/dev/cow_ram_snapshot1_0", O_RDONLY);
  if (rd_fd < 0) {
    printf("error opening device\n");
    return -1;
  }
  int err = ioctl(rd_fd, 0xff08);
  if (err < 0) {
    printf("error with ioctl\n");
    return -2;
  }
  close(rd_fd);
  return err;
}


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)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1190 <main+0x50>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <main+0x90>
mov    -0x14(%rbp),%edi
mov    $0xff08,%esi
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11c2 <main+0x82>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d0 <main+0x90>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1179 <main+0x39>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xff08,%esi
call   1040 <ioctl@plt>
test   %eax,%eax
js     118c <main+0x4c>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
jmp    119d <main+0x5d>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    119d <main+0x5d>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/dev/cow_ram_snapshot1_0\00"
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"error opening device\0A\00"
@.str.2 = [18 x i8] c"error with ioctl\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
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
14: ; preds = %2
%15 = load i32, i32* %6
%16 = call i32 @ioctl(i32 %15, i32 65288)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %25
21: ; preds = %14
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* %7
store i32 %24, i32* %3
br label %25
25: ; preds = %21, %19, %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [25 x i8] c"/dev/cow_ram_snapshot1_0\00"
@O_RDONLY = global i32 0
@str = [17 x i8] c"error with ioctl\00"
@str.3 = [21 x i8] c"error opening device\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.3, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @ioctl(i32 %4, i32 65288)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %15
13: ; preds = %8
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %11, %13, %6
%16 = phi i32 [ -1, %6 ], [ -2, %11 ], [ %9, %13 ]
ret i32 %16
}