#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 */
typedef size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int close(int);
int /*<<< orphan*/ die(char *, ...);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char *);
int /*<<< orphan*/ free(char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int mount(char *, char *, char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char const *, int /*<<< orphan*/);
size_t read(int, char *, size_t);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ umount_buffer(char *);
char *xmalloc(size_t);
void umount_all(void) {
  static const char mounts[] = "/proc/self/mounts";
  char *buf;
  ssize_t bufsz, bytes;
  int fd, result;
  buf = NULL;
  bufsz = 4096;
  result = mount("proc", "/proc", "proc", 0, NULL);
  if (result < 0)
    die("mount of proc failed: %d: %s\n", errno, strerror(errno));
  fd = open(mounts, O_RDONLY);
  if (fd < 0)
    die("open of %s failed: %d: %s\n", mounts, errno, strerror(errno));
  do {
    buf = xmalloc(bufsz);
    result = lseek(fd, 0, SEEK_SET);
    if (result != 0)
      die("lseek failed: %d:%s\n", errno, strerror(errno));
    bytes = read(fd, buf, bufsz);
    if (bytes < 0)
      die("Read of %s failed: %d:%s\n", mounts, errno, strerror(errno));
    if (bytes != bufsz) {
      buf[bytes] = '\0';
    } else {
      free(buf);
      buf = NULL;
      bufsz <<= 1;
    }
  } while (!buf);
  result = close(fd);
  if (result < 0)
    fprintf(stderr, "close of %s failed: %d:%s\n", mounts, errno,
            strerror(errno));
  umount_buffer(buf);
}


x86 assembly (clang, -O0):
<umount_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x1000,-0x10(%rbp)
lea    0xe44(%rip),%rdx
lea    0xe3c(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rdx,%rdi
call   1050 <mount@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1220 <umount_all+0x70>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   10c0 <die@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xdd0(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1277 <umount_all+0xc7>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
lea    0xdcd(%rip),%rdi
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   10c0 <die@plt>
jmp    127c <umount_all+0xcc>
mov    -0x10(%rbp),%rdi
call   1070 <xmalloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12d7 <umount_all+0x127>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2c(%rbp),%esi
mov    %rax,%rdx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   10c0 <die@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    132b <umount_all+0x17b>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xd49(%rip),%rdi
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   10c0 <die@plt>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     134a <umount_all+0x19a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1367 <umount_all+0x1b7>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    136c <umount_all+0x1bc>
cmpq   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    127c <umount_all+0xcc>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13d5 <umount_all+0x225>
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2c2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%ecx
mov    %rax,%r8
lea    0xcb7(%rip),%rsi
lea    0xc30(%rip),%rdx
call   10a0 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <umount_buffer@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<umount_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe50(%rip),%rsi
lea    0xe4a(%rip),%rdi
mov    %rdi,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <mount@plt>
test   %eax,%eax
jns    11fd <umount_all+0x4d>
mov    0x2def(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xe27(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <die@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xdf3(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1243 <umount_all+0x93>
mov    0x2db0(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
lea    0xe06(%rip),%rdi
lea    0xdc9(%rip),%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10c0 <die@plt>
mov    $0x1000,%ebp
mov    0x2d79(%rip),%r13
lea    0xdfb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <xmalloc@plt>
mov    %rax,%r12
mov    0x0(%r13),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %eax,%eax
je     129c <umount_all+0xec>
mov    0x2d4c(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10d0 <strerror@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <die@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1090 <read@plt>
cmp    %rbp,%rax
jne    12bc <umount_all+0x10c>
mov    %r12,%rdi
call   1030 <free@plt>
add    %rbp,%rbp
jmp    1260 <umount_all+0xb0>
movb   $0x0,(%r12,%rax,1)
mov    %r14d,%edi
call   1080 <close@plt>
test   %eax,%eax
jns    1300 <umount_all+0x150>
mov    0x2d04(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf3(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10d0 <strerror@plt>
lea    0xd79(%rip),%rsi
lea    0xd0c(%rip),%rdx
mov    %ebx,%edi
mov    %ebp,%ecx
mov    %rax,%r8
call   10a0 <fprintf@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <umount_buffer@plt>

LLVM IR (-O0):
@umount_all.mounts = internal constant [18 x i8] c"/proc/self/mounts\00"
@.str = [5 x i8] c"proc\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [30 x i8] c"mount of proc failed: %d: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [27 x i8] c"open of %s failed: %d: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [21 x i8] c"lseek failed: %d:%s\0A\00"
@.str.5 = [26 x i8] c"Read of %s failed: %d:%s\0A\00"
@stderr = global i32 0
@.str.6 = [27 x i8] c"close of %s failed: %d:%s\0A\00"
define void @umount_all() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i8* null, i8** %1
store i64 4096, i64* %2
%6 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0, i32* null)
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* %12)
br label %14
14: ; preds = %9, %0
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %20, i8* %22)
br label %24
24: ; preds = %19, %14
br label %25
25: ; preds = %64, %24
%26 = load i64, i64* %2
%27 = call i8* @xmalloc(i64 %26)
store i8* %27, i8** %1
%28 = load i32, i32* %4
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @lseek(i32 %28, i32 0, i32 %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %25
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %34, i8* %36)
br label %38
38: ; preds = %33, %25
%39 = load i32, i32* %4
%40 = load i8*, i8** %1
%41 = load i64, i64* %2
%42 = call i64 @read(i32 %39, i8* %40, i64 %41)
store i64 %42, i64* %3
%43 = load i64, i64* %3
%44 = icmp ult i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = load i32, i32* @errno
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %46, i8* %48)
br label %50
50: ; preds = %45, %38
%51 = load i64, i64* %3
%52 = load i64, i64* %2
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i8*, i8** %1
%56 = load i64, i64* %3
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8 0, i8* %57
br label %63
58: ; preds = %50
%59 = load i8*, i8** %1
%60 = call i32 @free(i8* %59)
store i8* null, i8** %1
%61 = load i64, i64* %2
%62 = shl i64 %61, 1
store i64 %62, i64* %2
br label %63
63: ; preds = %58, %54
br label %64
64: ; preds = %63
%65 = load i8*, i8** %1
%66 = icmp ne i8* %65, null
%67 = xor i1 %66, true
br i1 %67, label %25, label %68
68: ; preds = %64
%69 = load i32, i32* %4
%70 = call i32 @close(i32 %69)
store i32 %70, i32* %5
%71 = load i32, i32* %5
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %75, i8* %77)
br label %79
79: ; preds = %73, %68
%80 = load i8*, i8** %1
%81 = call i32 @umount_buffer(i8* %80)
ret void
}

LLVM IR (-O2):
@umount_all.mounts = internal constant [18 x i8] c"/proc/self/mounts\00"
@.str = [5 x i8] c"proc\00"
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [30 x i8] c"mount of proc failed: %d: %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [27 x i8] c"open of %s failed: %d: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [21 x i8] c"lseek failed: %d:%s\0A\00"
@stderr = global i32 0
@.str.6 = [27 x i8] c"close of %s failed: %d:%s\0A\00"
define void @umount_all() {
%1 = tail call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0, i32* null)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i8* @strerror(i32 %4)
%6 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %4, i8* %5)
br label %7
7: ; preds = %3, %0
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %12, i8* %13)
br label %15
15: ; preds = %11, %7
br label %16
16: ; preds = %15, %29
%17 = phi i64 [ %31, %29 ], [ 4096, %15 ]
%18 = tail call i8* @xmalloc(i64 %17)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @lseek(i32 %9, i32 0, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %23, i8* %24)
br label %26
26: ; preds = %22, %16
%27 = tail call i64 @read(i32 %9, i8* %18, i64 %17)
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = tail call i32 @free(i8* %18)
%31 = shl i64 %17, 1
br label %16
32: ; preds = %26
%33 = getelementptr inbounds i8, i8* %18, i64 %27
store i8 0, i8* %33
%34 = tail call i32 @close(i32 %9)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = tail call i8* @strerror(i32 %38)
%40 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @umount_all.mounts, i64 0, i64 0), i32 %38, i8* %39)
br label %41
41: ; preds = %36, %32
%42 = tail call i32 @umount_buffer(i8* %18)
ret void
}