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


x86 assembly (clang, -O0):
<umount_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11aa <umount_main+0x3a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <umount_main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
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     11f2 <umount_main+0x82>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <umount_main+0x10a>
cmpl   $0x0,-0x14(%rbp)
je     1273 <umount_main+0x103>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jge    1236 <umount_main+0xc6>
lea    0xe04(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <umount_main+0x10a>
mov    -0x18(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    126b <umount_main+0xfb>
lea    0xde7(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    127a <umount_main+0x10a>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<umount_main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11a6 <umount_main+0x36>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <is_loop_mount@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   1030 <umount@plt>
test   %rax,%rax
je     11c9 <umount_main+0x59>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
jmp    11b6 <umount_main+0x46>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
test   %ebp,%ebp
je     120b <umount_main+0x9b>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe3b(%rip),%rdi
call   1080 <open@plt>
cmp    $0xfffffffe,%eax
jle    120f <umount_main+0x9f>
mov    %eax,%ebp
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1218 <umount_main+0xa8>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11c0 <umount_main+0x50>
xor    %ebx,%ebx
jmp    11c0 <umount_main+0x50>
lea    0xe13(%rip),%rdi
jmp    121f <umount_main+0xaf>
lea    0xe22(%rip),%rdi
call   1090 <perror@plt>
jmp    11bb <umount_main+0x4b>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"umount <path>\0A\00"
@.str.1 = [9 x i8] c"failed.\0A\00"
@.str.2 = [17 x i8] c"/dev/block/loop0\00"
@O_RDONLY = global i32 0
@.str.3 = [24 x i8] c"open loop device failed\00"
@LOOP_CLR_FD = global i32 0
@.str.4 = [25 x i8] c"ioctl LOOP_CLR_FD failed\00"
define i32 @umount_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 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %33
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @is_loop_mount(i8* %9)
%11 = load i8*, i8** %8
%12 = tail call i64 @umount(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %33
17: ; preds = %7
%18 = icmp eq i32 %10, 0
br i1 %18, label %33, label %19
19: ; preds = %17
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp slt i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %33
25: ; preds = %19
%26 = load i32, i32* @LOOP_CLR_FD
%27 = tail call i64 @ioctl(i32 %21, i32 %26, i32 0)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %33
31: ; preds = %25
%32 = tail call i32 @close(i32 %21)
br label %33
33: ; preds = %17, %31, %29, %23, %14, %4
%34 = phi i32 [ 1, %4 ], [ 1, %14 ], [ 1, %23 ], [ 1, %29 ], [ 0, %31 ], [ 0, %17 ]
ret i32 %34
}