#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();
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 *);
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/kawamuray/criu/refs/"
                   "heads/master/test/mounts/ext/ext-mount.c",
                   33);
    return -ENOTSUP;
  }
  dst = getenv("dfile");
  if (!dst) {
    print_on_level((1),
                   "Error (%s:%d): "
                   "No dfile env\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/kawamuray/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"
                   ": %m\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/"
                   "heads/master/test/mounts/ext/ext-mount.c",
                   53);
    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    0xe61(%rip),%rsi
mov    $0x0,%al
call   10a0 <print_on_level@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f5 <cr_plugin_dump_ext_mount+0x75>
mov    $0x1,%edi
lea    0xe54(%rip),%rsi
lea    0xe6f(%rip),%rdx
mov    $0x21,%ecx
mov    $0x0,%al
call   10a0 <print_on_level@plt>
xor    %eax,%eax
mov    0x2de5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    131e <cr_plugin_dump_ext_mount+0x19e>
lea    0xee0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123b <cr_plugin_dump_ext_mount+0xbb>
mov    $0x1,%edi
lea    0xec6(%rip),%rsi
lea    0xe22(%rip),%rdx
mov    $0x27,%ecx
mov    $0x0,%al
call   10a0 <print_on_level@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131e <cr_plugin_dump_ext_mount+0x19e>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     127c <cr_plugin_dump_ext_mount+0xfc>
mov    $0x3,%edi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   10a0 <print_on_level@plt>
xor    %eax,%eax
mov    0x2d5e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    131e <cr_plugin_dump_ext_mount+0x19e>
mov    -0x14(%rbp),%edx
mov    $0x3,%edi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   10a0 <print_on_level@plt>
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe7e(%rip),%rsi
call   1090 <sprintf@plt>
mov    $0x0,%al
call   1080 <criu_get_image_dir@plt>
mov    %eax,%edi
lea    -0x70(%rbp),%rsi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    0x2d36(%rip),%rax
or     (%rax),%edx
mov    0x2d25(%rip),%rax
or     (%rax),%edx
mov    $0x180,%ecx
call   1040 <openat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    130f <cr_plugin_dump_ext_mount+0x18f>
mov    $0x1,%edi
lea    0xe44(%rip),%rsi
lea    0xd4e(%rip),%rdx
mov    $0x35,%ecx
mov    $0x0,%al
call   10a0 <print_on_level@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131e <cr_plugin_dump_ext_mount+0x19e>
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    0xe6b(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <print_on_level@plt>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11f7 <cr_plugin_dump_ext_mount+0x77>
mov    %rax,%rbp
lea    0xf1a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1224 <cr_plugin_dump_ext_mount+0xa4>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1241 <cr_plugin_dump_ext_mount+0xc1>
lea    0xf18(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
xor    %eax,%eax
call   10a0 <print_on_level@plt>
jmp    1216 <cr_plugin_dump_ext_mount+0x96>
lea    0xe25(%rip),%rsi
lea    0xe40(%rip),%rdx
mov    $0x1,%edi
mov    $0x21,%ecx
xor    %eax,%eax
call   10a0 <print_on_level@plt>
mov    0x2db3(%rip),%rax
sub    (%rax),%ebx
jmp    12d0 <cr_plugin_dump_ext_mount+0x150>
lea    0xeb7(%rip),%rsi
lea    0xe13(%rip),%rdx
mov    $0x1,%edi
mov    $0x27,%ecx
jmp    12c4 <cr_plugin_dump_ext_mount+0x144>
lea    0xec1(%rip),%rsi
xor    %ebx,%ebx
mov    $0x3,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   10a0 <print_on_level@plt>
lea    0xebe(%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    0x2d5c(%rip),%rcx
mov    0x2d75(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d62(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x180,%ecx
call   1040 <openat@plt>
test   %eax,%eax
js     12ac <cr_plugin_dump_ext_mount+0x12c>
mov    %eax,%edi
call   1060 <close@plt>
jmp    12d0 <cr_plugin_dump_ext_mount+0x150>
lea    0xe81(%rip),%rsi
lea    0xd8b(%rip),%rdx
mov    $0x1,%edi
mov    $0x35,%ecx
xor    %eax,%eax
call   10a0 <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 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/mounts/ext/ext-mount.c\00"
@ENOTSUP = global i32 0
@.str.3 = [6 x i8] c"dfile\00"
@.str.4 = [29 x i8] c"Error (%s:%d): No dfile 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: %m\0A\00"
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 ([151 x i8], [151 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 %57
20: ; preds = %2
%21 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 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 ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 39)
store i32 -1, i32* %3
br label %57
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 %57
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 %54
52: ; preds = %36
%53 = 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 ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 53)
store i32 -1, i32* %3
br label %57
54: ; preds = %36
%55 = load i32, i32* %8
%56 = call i32 @close(i32 %55)
store i32 0, i32* %3
br label %57
57: ; preds = %54, %52, %32, %24, %16
%58 = load i32, i32* %3
ret i32 %58
}

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 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/mounts/ext/ext-mount.c\00"
@ENOTSUP = global i32 0
@.str.3 = [6 x i8] c"dfile\00"
@.str.4 = [29 x i8] c"Error (%s:%d): No dfile 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: %m\0A\00"
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 ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 33)
%10 = load i32, i32* @ENOTSUP
%11 = sub nsw i32 0, %10
br label %40
12: ; preds = %2
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 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 ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 39)
br label %40
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 %40
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 %38
36: ; preds = %25
%37 = 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 ([151 x i8], [151 x i8]* @.str.2, i64 0, i64 0), i32 53)
br label %40
38: ; preds = %25
%39 = call i32 @close(i32 %34)
br label %40
40: ; preds = %38, %36, %21, %15, %8
%41 = phi i32 [ %24, %21 ], [ -1, %36 ], [ 0, %38 ], [ -1, %15 ], [ %11, %8 ]
ret i32 %41
}