#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 /*<<< orphan*/ ioctl(int, int, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int crypt_loop_resize(const char *loop) {
  int loop_fd = -1, r = 1;
  loop_fd = open(loop, O_RDONLY);
  if (loop_fd < 0)
    return 1;
  if (!ioctl(loop_fd, 0x4C07, 0))
    r = 0;
  close(loop_fd);
  return r;
}


x86 assembly (clang, -O0):
<crypt_loop_resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1175 <crypt_loop_resize+0x45>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <crypt_loop_resize+0x72>
mov    -0x14(%rbp),%edi
mov    $0x4c07,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%eax
jne    1194 <crypt_loop_resize+0x64>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt_loop_resize>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1166 <crypt_loop_resize+0x36>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x4c07,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebx,%edi
call   1040 <close@plt>
jmp    116b <crypt_loop_resize+0x3b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @crypt_loop_resize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 1, i32* %5
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %21
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i32 @ioctl(i32 %13, i32 19463, i32 0)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12
store i32 0, i32* %5
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %4
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %5
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @crypt_loop_resize(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 @ioctl(i32 %3, i32 19463, i32 0)
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @close(i32 %3)
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %8, %5 ], [ 1, %1 ]
ret i32 %11
}