#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*/ LOOP_CLR_FD;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int is_loop_mount(char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ umount(char *);
int umount_main(int argc, char *argv[]) {
  int loop, loop_fd;
  char loopdev[64];
  if (argc != 2) {
    fprintf(stderr, "umount <path>\n");
    return 1;
  }
  loop = is_loop_mount(argv[1], loopdev);
  if (umount(argv[1])) {
    fprintf(stderr, "failed: %s\n", strerror(errno));
    return 1;
  }
  if (loop) {
    loop_fd = open(loopdev, O_RDONLY);
    if (loop_fd < 0) {
      fprintf(stderr, "open loop device failed: %s\n", strerror(errno));
      return 1;
    }
    if (ioctl(loop_fd, LOOP_CLR_FD, 0) < 0) {
      fprintf(stderr, "ioctl LOOP_CLR_FD failed: %s\n", strerror(errno));
      return 1;
    }
    close(loop_fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<umount_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ac <umount_main+0x3c>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <umount_main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x60(%rbp),%rsi
call   1070 <is_loop_mount@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <umount@plt>
cmp    $0x0,%rax
je     1211 <umount_main+0xa1>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <umount_main+0x16a>
cmpl   $0x0,-0x14(%rbp)
je     12d3 <umount_main+0x163>
lea    -0x60(%rbp),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1274 <umount_main+0x104>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <umount_main+0x16a>
mov    -0x18(%rbp),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    12cb <umount_main+0x15b>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <umount_main+0x16a>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<umount_main>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
cmp    $0x2,%edi
jne    11c6 <umount_main+0x56>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1070 <is_loop_mount@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   1030 <umount@plt>
test   %rax,%rax
je     11eb <umount_main+0x7b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe86(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11dd <umount_main+0x6d>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
test   %ebp,%ebp
je     1228 <umount_main+0xb8>
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     122c <umount_main+0xbc>
mov    %eax,%ebp
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     124f <umount_main+0xdf>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11e2 <umount_main+0x72>
xor    %ebx,%ebx
jmp    11e2 <umount_main+0x72>
mov    0x2d9d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc5(%rip),%rsi
jmp    11b8 <umount_main+0x48>
mov    0x2d7a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdbf(%rip),%rsi
jmp    11b8 <umount_main+0x48>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"umount <path>\0A\00"
@.str.1 = [12 x i8] c"failed: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [29 x i8] c"open loop device failed: %s\0A\00"
@LOOP_CLR_FD = global i32 0
@.str.3 = [30 x i8] c"ioctl LOOP_CLR_FD failed: %s\0A\00"
define i32 @umount_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %58
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%19 = call i32 @is_loop_mount(i8* %17, i8* %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @umount(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %58
30: ; preds = %14
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %57
33: ; preds = %30
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
br label %58
44: ; preds = %33
%45 = load i32, i32* %7
%46 = load i32, i32* @LOOP_CLR_FD
%47 = call i64 @ioctl(i32 %45, i32 %46, i32 0)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %52)
store i32 1, i32* %3
br label %58
54: ; preds = %44
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
br label %57
57: ; preds = %54, %30
store i32 0, i32* %3
br label %58
58: ; preds = %57, %49, %39, %25, %11
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"umount <path>\0A\00"
@.str.1 = [12 x i8] c"failed: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [29 x i8] c"open loop device failed: %s\0A\00"
@LOOP_CLR_FD = global i32 0
@.str.3 = [30 x i8] c"ioctl LOOP_CLR_FD failed: %s\0A\00"
define i32 @umount_main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %43
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @is_loop_mount(i8* %11, i8* %4)
%13 = load i8*, i8** %10
%14 = call i64 @umount(i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %43
21: ; preds = %9
%22 = icmp eq i32 %12, 0
br i1 %22, label %43, label %23
23: ; preds = %21
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %4, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %43
32: ; preds = %23
%33 = load i32, i32* @LOOP_CLR_FD
%34 = call i64 @ioctl(i32 %25, i32 %33, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %43
41: ; preds = %32
%42 = call i32 @close(i32 %25)
br label %43
43: ; preds = %21, %41, %36, %27, %16, %6
%44 = phi i32 [ 1, %6 ], [ 1, %16 ], [ 1, %27 ], [ 1, %36 ], [ 0, %41 ], [ 0, %21 ]
ret i32 %44
}