#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 int /*<<< orphan*/ pathname;
typedef int /*<<< orphan*/ file;

/* Variables and functions */
int MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
char *dmtcp_get_ckpt_dir();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int readall(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *read_dmtcp_env_file(char *file, int size) {
  char *buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
                   MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  if (buf == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }
  char pathname[512];
  if (strlen(dmtcp_get_ckpt_dir()) > sizeof(pathname) - 1 - sizeof(file)) {
    fprintf(stderr, "%s:%d : Pathname of ckpt dir is too long: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/onyeka/dmtcp/refs/heads/master/plugin/"
            "modify-env/modify-env.c",
            78, dmtcp_get_ckpt_dir());
    exit(1);
  }
  strcpy(pathname, dmtcp_get_ckpt_dir());
  strcpy(pathname + strlen(dmtcp_get_ckpt_dir()), "/");
  strcpy(pathname + strlen(dmtcp_get_ckpt_dir()) + strlen("/"), file);
  int fd = open(pathname, O_RDONLY);
  if (fd < 0) {
    perror("open");
    exit(1);
  }
  int count = readall(fd, buf, size);
  if (count < 0) {
    perror("read");
    exit(1);
  }
  *(buf + count) = ((char)-1);
  close(fd);
  return buf;
}


x86 assembly (clang, -O0):
<read_dmtcp_env_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    0x2dfb(%rip),%rax
or     (%rax),%edx
mov    0x2e0a(%rip),%rax
mov    (%rax),%ecx
mov    0x2de1(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%rax
jne    1219 <read_dmtcp_env_file+0x79>
lea    0xdf6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x1f7,%rax
jbe    1277 <read_dmtcp_env_file+0xd7>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    $0x0,%al
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    -0x22c(%rbp),%edi
mov    %rax,%r8
lea    0xda9(%rip),%rsi
lea    0xdd0(%rip),%rdx
mov    $0x4e,%ecx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    $0x0,%al
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    -0x250(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    $0x0,%al
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    -0x248(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe00(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    $0x0,%al
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x240(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x238(%rbp)
lea    0xdc1(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x238(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    1362 <read_dmtcp_env_file+0x1c2>
lea    0xd7a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x224(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10a0 <readall@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0x0,-0x228(%rbp)
jge    139d <read_dmtcp_env_file+0x1fd>
lea    0xd44(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x228(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x224(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_dmtcp_env_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
mov    0x2e3a(%rip),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e08(%rip),%rax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
mov    0x2dbb(%rip),%rax
cmp    (%rax),%rbx
je     12c6 <read_dmtcp_env_file+0x126>
xor    %eax,%eax
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x1f8,%eax
jae    12cf <read_dmtcp_env_file+0x12f>
xor    %eax,%eax
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
lea    0xe82(%rip),%r13
mov    %r13,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   10c0 <dmtcp_get_ckpt_dir@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1306 <read_dmtcp_env_file+0x166>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10a0 <readall@plt>
test   %eax,%eax
js     130f <read_dmtcp_env_file+0x16f>
mov    %eax,%eax
movb   $0xff,(%rbx,%rax,1)
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd33(%rip),%rdi
jmp    1316 <read_dmtcp_env_file+0x176>
mov    0x2cf2(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <dmtcp_get_ckpt_dir@plt>
lea    0xd1f(%rip),%rsi
lea    0xd46(%rip),%rdx
mov    %ebx,%edi
mov    $0x4e,%ecx
mov    %rax,%r8
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdc0(%rip),%rdi
jmp    1316 <read_dmtcp_env_file+0x176>
lea    0xdbc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"%s:%d : Pathname of ckpt dir is too long: %s\0A\00"
@.str.2 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/onyeka/dmtcp/refs/heads/master/plugin/modify-env/modify-env.c\00"
@.str.3 = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"read\00"
define i8* @read_dmtcp_env_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %10, %11
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = load i32, i32* @MAP_PRIVATE
%15 = or i32 %13, %14
%16 = call i8* @mmap(i32* null, i32 %9, i32 %12, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = call i8* (...) @dmtcp_get_ckpt_dir()
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = icmp ugt i64 %26, 503
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i8* (...) @dmtcp_get_ckpt_dir()
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.2, i64 0, i64 0), i32 78, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%35 = call i8* (...) @dmtcp_get_ckpt_dir()
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%38 = call i8* (...) @dmtcp_get_ckpt_dir()
%39 = call i32 @strlen(i8* %38)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%44 = call i8* (...) @dmtcp_get_ckpt_dir()
%45 = call i32 @strlen(i8* %44)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8*, i8** %3
%52 = call i32 @strcpy(i8* %50, i8* %51)
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%54 = load i32, i32* @O_RDONLY
%55 = call i32 @open(i8* %53, i32 %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %33
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %33
%62 = load i32, i32* %7
%63 = load i8*, i8** %5
%64 = load i32, i32* %4
%65 = call i32 @readall(i32 %62, i8* %63, i32 %64)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %61
%72 = load i8*, i8** %5
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 -1, i8* %75
%76 = load i32, i32* %7
%77 = call i32 @close(i32 %76)
%78 = load i8*, i8** %5
ret i8* %78
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"%s:%d : Pathname of ckpt dir is too long: %s\0A\00"
@.str.2 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/onyeka/dmtcp/refs/heads/master/plugin/modify-env/modify-env.c\00"
@.str.3 = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [5 x i8] c"read\00"
define i8* @read_dmtcp_env_file(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @PROT_WRITE
%6 = or i32 %5, %4
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = load i32, i32* @MAP_PRIVATE
%9 = or i32 %8, %7
%10 = tail call i8* @mmap(i32* null, i32 %1, i32 %6, i32 %9, i32 -1, i32 0)
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%18 = tail call i8* (...) @dmtcp_get_ckpt_dir()
%19 = tail call i32 @strlen(i8* %18)
%20 = icmp ugt i32 %19, 503
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i8* (...) @dmtcp_get_ckpt_dir()
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.2, i64 0, i64 0), i32 78, i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = tail call i8* (...) @dmtcp_get_ckpt_dir()
%28 = call i32 @strcpy(i8* %17, i8* %27)
%29 = call i8* (...) @dmtcp_get_ckpt_dir()
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %31
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = call i8* (...) @dmtcp_get_ckpt_dir()
%35 = call i32 @strlen(i8* %34)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %36
%38 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i32 @strcpy(i8* %40, i8* %0)
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %17, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %26
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %26
%49 = call i32 @readall(i32 %43, i8* %10, i32 %1)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %48
%55 = zext i32 %49 to i64
%56 = getelementptr inbounds i8, i8* %10, i64 %55
store i8 -1, i8* %56
%57 = call i32 @close(i32 %43)
ret i8* %10
}