#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 ENOTSUP;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ criu_get_image_dir();
int /*<<< orphan*/ errno;
char *getenv(char *);
int openat(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ print_on_level(int, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strrchr(char *, char);
int cr_plugin_dump_ext_mount(char *mountpoint, int id) {
  char *aux, *dst;
  int fd;
  char img[64];
  print_on_level((3), "Check for ext mount %s being mine\n", mountpoint);
  aux = strrchr(mountpoint, '/');
  if (!aux) {
    print_on_level((1),
                   "Error (%s:%d): "
                   "Bad path provided\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/"
                   "refs/heads/master/test/mounts/ext/ext-mount.c",
                   33);
    return -ENOTSUP;
  }
  dst = getenv("EMP_MOUNTPOINT");
  if (!dst) {
    print_on_level((1),
                   "Error (%s:%d): "
                   "No EMP_MOUNTPOINT env\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/"
                   "refs/heads/master/test/mounts/ext/ext-mount.c",
                   39);
    return -1;
  }
  if (strcmp(aux + 1, dst)) {
    print_on_level((3), "Not mine\n");
    return -ENOTSUP;
  }
  print_on_level((3), "Dumping my mount %d\n", id);
  sprintf(img, "ext-mount-test-%d.img", id);
  fd = openat(criu_get_image_dir(), img, O_RDWR | O_CREAT | O_TRUNC, 0600);
  if (fd < 0) {
    print_on_level((1),
                   "Error (%s:%d): "
                   "Can't open image"
                   ": %s\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/"
                   "refs/heads/master/test/mounts/ext/ext-mount.c",
                   53, strerror(errno));
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<cr_plugin_dump_ext_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x3,%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   10b0 <print_on_level@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <cr_plugin_dump_ext_mount+0x75>
mov    $0x1,%edi
lea    0xe44(%rip),%rsi
lea    0xe5f(%rip),%rdx
mov    $0x21,%ecx
mov    $0x0,%al
call   10b0 <print_on_level@plt>
xor    %eax,%eax
mov    0x2dd5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <cr_plugin_dump_ext_mount+0x1af>
lea    0xed9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124b <cr_plugin_dump_ext_mount+0xbb>
mov    $0x1,%edi
lea    0xec8(%rip),%rsi
lea    0xe12(%rip),%rdx
mov    $0x27,%ecx
mov    $0x0,%al
call   10b0 <print_on_level@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <cr_plugin_dump_ext_mount+0x1af>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     128c <cr_plugin_dump_ext_mount+0xfc>
mov    $0x3,%edi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   10b0 <print_on_level@plt>
xor    %eax,%eax
mov    0x2d4e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <cr_plugin_dump_ext_mount+0x1af>
mov    -0x14(%rbp),%edx
mov    $0x3,%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   10b0 <print_on_level@plt>
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe89(%rip),%rsi
call   1090 <sprintf@plt>
mov    $0x0,%al
call   1080 <criu_get_image_dir@plt>
mov    %eax,%edi
lea    -0x70(%rbp),%rsi
mov    0x2d0f(%rip),%rax
mov    (%rax),%edx
mov    0x2d26(%rip),%rax
or     (%rax),%edx
mov    0x2d15(%rip),%rax
or     (%rax),%edx
mov    $0x180,%ecx
call   1040 <openat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1330 <cr_plugin_dump_ext_mount+0x1a0>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xe3e(%rip),%rsi
lea    0xd2d(%rip),%rdx
mov    $0x35,%ecx
mov    $0x0,%al
call   10b0 <print_on_level@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <cr_plugin_dump_ext_mount+0x1af>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cr_plugin_dump_ext_mount>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe5b(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <print_on_level@plt>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1207 <cr_plugin_dump_ext_mount+0x77>
mov    %rax,%rbp
lea    0xf13(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1234 <cr_plugin_dump_ext_mount+0xa4>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1258 <cr_plugin_dump_ext_mount+0xc8>
lea    0xf23(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
xor    %eax,%eax
call   10b0 <print_on_level@plt>
jmp    1226 <cr_plugin_dump_ext_mount+0x96>
lea    0xe15(%rip),%rsi
lea    0xe30(%rip),%rdx
mov    $0x1,%edi
mov    $0x21,%ecx
xor    %eax,%eax
call   10b0 <print_on_level@plt>
mov    0x2da3(%rip),%rax
sub    (%rax),%ebx
jmp    12f8 <cr_plugin_dump_ext_mount+0x168>
lea    0xeb9(%rip),%rsi
lea    0xe03(%rip),%rdx
mov    $0x1,%edi
mov    $0x27,%ecx
xor    %eax,%eax
call   10b0 <print_on_level@plt>
jmp    12f3 <cr_plugin_dump_ext_mount+0x163>
lea    0xec5(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <print_on_level@plt>
lea    0xec2(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14d,%edx
call   1090 <sprintf@plt>
xor    %eax,%eax
call   1080 <criu_get_image_dir@plt>
mov    0x2d45(%rip),%rcx
mov    0x2d5e(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d4b(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x180,%ecx
call   1040 <openat@plt>
test   %eax,%eax
js     12c3 <cr_plugin_dump_ext_mount+0x133>
mov    %eax,%edi
call   1060 <close@plt>
jmp    12f8 <cr_plugin_dump_ext_mount+0x168>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe77(%rip),%rsi
lea    0xd66(%rip),%rdx
mov    $0x1,%edi
mov    $0x35,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   10b0 <print_on_level@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Check for ext mount %s being mine\0A\00"
@.str.1 = [34 x i8] c"Error (%s:%d): Bad path provided\0A\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/mounts/ext/ext-mount.c\00"
@ENOTSUP = global i32 0
@.str.3 = [15 x i8] c"EMP_MOUNTPOINT\00"
@.str.4 = [38 x i8] c"Error (%s:%d): No EMP_MOUNTPOINT env\0A\00"
@.str.5 = [10 x i8] c"Not mine\0A\00"
@.str.6 = [21 x i8] c"Dumping my mount %d\0A\00"
@.str.7 = [22 x i8] c"ext-mount-test-%d.img\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [37 x i8] c"Error (%s:%d): Can't open image: %s\0A\00"
@errno = global i32 0
define i32 @cr_plugin_dump_ext_mount(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [64 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %4
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 33)
%18 = load i32, i32* @ENOTSUP
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %59
20: ; preds = %2
%21 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 39)
store i32 -1, i32* %3
br label %59
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8*, i8** %7
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @ENOTSUP
%35 = sub nsw i32 0, %34
store i32 %35, i32* %3
br label %59
36: ; preds = %26
%37 = load i32, i32* %5
%38 = call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* %5
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = call i32 (...) @criu_get_image_dir()
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%44 = load i32, i32* @O_RDWR
%45 = load i32, i32* @O_CREAT
%46 = or i32 %44, %45
%47 = load i32, i32* @O_TRUNC
%48 = or i32 %46, %47
%49 = call i32 @openat(i32 %42, i8* %43, i32 %48, i32 384)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %36
%53 = load i32, i32* @errno
%54 = call i32 @strerror(i32 %53)
%55 = call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 53, i32 %54)
store i32 -1, i32* %3
br label %59
56: ; preds = %36
%57 = load i32, i32* %8
%58 = call i32 @close(i32 %57)
store i32 0, i32* %3
br label %59
59: ; preds = %56, %52, %32, %24, %16
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [35 x i8] c"Check for ext mount %s being mine\0A\00"
@.str.1 = [34 x i8] c"Error (%s:%d): Bad path provided\0A\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/mounts/ext/ext-mount.c\00"
@ENOTSUP = global i32 0
@.str.3 = [15 x i8] c"EMP_MOUNTPOINT\00"
@.str.4 = [38 x i8] c"Error (%s:%d): No EMP_MOUNTPOINT env\0A\00"
@.str.5 = [10 x i8] c"Not mine\0A\00"
@.str.6 = [21 x i8] c"Dumping my mount %d\0A\00"
@.str.7 = [22 x i8] c"ext-mount-test-%d.img\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [37 x i8] c"Error (%s:%d): Can't open image: %s\0A\00"
@errno = global i32 0
define i32 @cr_plugin_dump_ext_mount(i8* %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 33)
%10 = load i32, i32* @ENOTSUP
%11 = sub nsw i32 0, %10
br label %42
12: ; preds = %2
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 39)
br label %42
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %6, i64 1
%19 = tail call i64 @strcmp(i8* %18, i8* %13)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = tail call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%23 = load i32, i32* @ENOTSUP
%24 = sub nsw i32 0, %23
br label %42
25: ; preds = %17
%26 = tail call i32 (i32, i8*, ...) @print_on_level(i32 3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %1)
%27 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %1)
%28 = tail call i32 (...) @criu_get_image_dir()
%29 = load i32, i32* @O_RDWR
%30 = load i32, i32* @O_CREAT
%31 = or i32 %30, %29
%32 = load i32, i32* @O_TRUNC
%33 = or i32 %31, %32
%34 = call i32 @openat(i32 %28, i8* %4, i32 %33, i32 384)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %25
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 (i32, i8*, ...) @print_on_level(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 53, i32 %38)
br label %42
40: ; preds = %25
%41 = call i32 @close(i32 %34)
br label %42
42: ; preds = %40, %36, %21, %15, %8
%43 = phi i32 [ %24, %21 ], [ -1, %36 ], [ 0, %40 ], [ -1, %15 ], [ %11, %8 ]
ret i32 %43
}