#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*/ uint64_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int getdelim(char **, size_t *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int u64_fseek(int /*<<< orphan*/ *, int /*<<< orphan*/);
int read_mem_str(char **line, size_t *n, FILE *m, uint64_t off) {
  int p = u64_fseek(m, off);
  if (p == -1) {
    perror("fseek /proc/$pid/mem failed");
    return -1;
  }
  ssize_t r = getdelim(line, n, 0, m);
  if (r == -1) {
    perror(0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_mem_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <u64_fseek@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1178 <read_mem_str+0x48>
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <read_mem_str+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1050 <getdelim@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11ad <read_mem_str+0x7d>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <read_mem_str+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_mem_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
mov    %ecx,%esi
call   1040 <u64_fseek@plt>
cmp    $0xffffffff,%eax
je     1177 <read_mem_str+0x47>
xor    %r14d,%r14d
mov    %r12,%rdi
mov    %r15,%rsi
xor    %edx,%edx
mov    %rbx,%rcx
call   1050 <getdelim@plt>
cmp    $0xffffffff,%eax
je     117e <read_mem_str+0x4e>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe82(%rip),%r14
mov    %r14,%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1168 <read_mem_str+0x38>

LLVM IR (-O0):
@.str = [28 x i8] c"fseek /proc/$pid/mem failed\00"
define i32 @read_mem_str(i8** %0, i64* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%12 = load i32*, i32** %8
%13 = load i32, i32* %9
%14 = call i32 @u64_fseek(i32* %12, i32 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %29
19: ; preds = %4
%20 = load i8**, i8*** %6
%21 = load i64*, i64** %7
%22 = load i32*, i32** %8
%23 = call i32 @getdelim(i8** %20, i64* %21, i32 0, i32* %22)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* null)
store i32 -1, i32* %5
br label %29
28: ; preds = %19
store i32 0, i32* %5
br label %29
29: ; preds = %28, %26, %17
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@.str = [28 x i8] c"fseek /proc/$pid/mem failed\00"
define i32 @read_mem_str(i8** %0, i64* %1, i32* %2, i32 %3) {
%5 = tail call i32 @u64_fseek(i32* %2, i32 %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @getdelim(i8** %0, i64* %1, i32 0, i32* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7, %4
%11 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %4 ], [ null, %7 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ 0, %7 ], [ -1, %10 ]
ret i32 %14
}