#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 */
scalar_t__ EBUSY;
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ logger(int, scalar_t__, char *, char *);
int /*<<< orphan*/ sleep(int);
int umount2(char *, int);
int real_umount(unsigned int veid, char *root) {
  int i, ret, n;
  n = 0;
  for (i = 0; i < 2; i++) {
    while (1) {
      ret = umount2(root, 0x00000002);
      if (ret < 0) {
        if (n > 0 && errno == EINVAL)
          ret = 0;
        break;
      }
      n++;
    }
    if (ret == 0 || (ret < 0 && errno != EBUSY))
      break;
    sleep(1);
  }
  if (ret) {
    logger(-1, errno, "Can't umount: %s", root);
    ret = 51;
  }
  return ret;
}


x86 assembly (clang, -O0):
<real_umount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1200 <real_umount+0xd0>
jmp    115c <real_umount+0x2c>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <umount2@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a7 <real_umount+0x77>
cmpl   $0x0,-0x1c(%rbp)
jle    11a2 <real_umount+0x72>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    11a2 <real_umount+0x72>
movl   $0x0,-0x18(%rbp)
jmp    11b5 <real_umount+0x85>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <real_umount+0x2c>
cmpl   $0x0,-0x18(%rbp)
je     11e3 <real_umount+0xb3>
cmpl   $0x0,-0x18(%rbp)
jge    11e8 <real_umount+0xb8>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
je     11e8 <real_umount+0xb8>
jmp    1200 <real_umount+0xd0>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <real_umount+0x1d>
cmpl   $0x0,-0x18(%rbp)
je     1230 <real_umount+0x100>
mov    0x2dcf(%rip),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xddc(%rip),%rdx
call   1040 <logger@plt>
movl   $0x33,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_umount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <umount2@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
jns    1150 <real_umount+0x20>
xor    %r14d,%r14d
mov    0x2e72(%rip),%r15
mov    (%r15),%rsi
mov    0x2e60(%rip),%r12
cmp    $0x1,%ebp
je     1183 <real_umount+0x53>
cmp    (%r12),%rsi
je     11ee <real_umount+0xbe>
mov    0x2e46(%rip),%r13
cmp    0x0(%r13),%rsi
jne    11d4 <real_umount+0xa4>
mov    $0x1,%edi
call   1050 <sleep@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <umount2@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
jns    11a0 <real_umount+0x70>
mov    (%r15),%rsi
test   %ebp,%ebp
je     11c1 <real_umount+0x91>
cmp    (%r12),%rsi
je     11ee <real_umount+0xbe>
cmp    0x0(%r13),%rsi
jne    11d4 <real_umount+0xa4>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    (%r15),%rsi
lea    0xe25(%rip),%rdx
mov    $0xffffffff,%edi
mov    %rbx,%rcx
call   1040 <logger@plt>
mov    $0x33,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@EBUSY = global i64 0
@.str = [17 x i8] c"Can't umount: %s\00"
define i32 @real_umount(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %42, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %45
11: ; preds = %8
br label %12
12: ; preds = %11, %26
%13 = load i8*, i8** %4
%14 = call i32 @umount2(i8* %13, i32 2)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %12
%18 = load i32, i32* %7
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINVAL
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %6
br label %25
25: ; preds = %24, %20, %17
br label %29
26: ; preds = %12
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %12
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i64, i64* @errno
%37 = load i64, i64* @EBUSY
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35, %29
br label %45
40: ; preds = %35, %32
%41 = call i32 @sleep(i32 1)
br label %42
42: ; preds = %40
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %8
45: ; preds = %39, %8
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i64, i64* @errno
%50 = load i8*, i8** %4
%51 = call i32 @logger(i32 -1, i64 %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %50)
store i32 51, i32* %6
br label %52
52: ; preds = %48, %45
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@EBUSY = global i64 0
@.str = [17 x i8] c"Can't umount: %s\00"
define i32 @real_umount(i32 %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ %7, %3 ], [ 0, %2 ]
%5 = tail call i32 @umount2(i8* %1, i32 2)
%6 = icmp slt i32 %5, 0
%7 = add nuw nsw i32 %4, 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = icmp ne i32 %4, 0
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINVAL
%12 = icmp eq i64 %10, %11
%13 = select i1 %9, i1 %12, i1 false
br i1 %13, label %39, label %14
14: ; preds = %8
%15 = load i64, i64* @EBUSY
%16 = icmp eq i64 %10, %15
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = tail call i32 @sleep(i32 1)
br label %19
19: ; preds = %19, %17
%20 = phi i32 [ %23, %19 ], [ %4, %17 ]
%21 = tail call i32 @umount2(i8* %1, i32 2)
%22 = icmp slt i32 %21, 0
%23 = add nuw nsw i32 %20, 1
br i1 %22, label %24, label %19
24: ; preds = %19
%25 = icmp ne i32 %20, 0
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINVAL
%28 = icmp eq i64 %26, %27
%29 = select i1 %25, i1 %28, i1 false
br i1 %29, label %39, label %30
30: ; preds = %24
%31 = load i64, i64* @EBUSY
%32 = icmp eq i64 %26, %31
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = tail call i32 @sleep(i32 1)
%35 = load i64, i64* @errno
br label %36
36: ; preds = %33, %30, %14
%37 = phi i64 [ %35, %33 ], [ %26, %30 ], [ %10, %14 ]
%38 = tail call i32 @logger(i32 -1, i64 %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %39
39: ; preds = %8, %24, %36
%40 = phi i32 [ 51, %36 ], [ 0, %24 ], [ 0, %8 ]
ret i32 %40
}