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

/* Variables and functions */
int /*<<< orphan*/ __softboundmpx_read_shadow_stack_metadata_store(char **,
                                                                   int);
int /*<<< orphan*/ __softboundmpx_store_return_metadata(char *, char *);
int /*<<< orphan*/ getdelim(char **, size_t *, int, int /*<<< orphan*/ *);
int strlen(char *);
__attribute__((__weak__, __always___)) ssize_t
softboundmpx___getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
  int metadata_prop = 1;
  if (*lineptr == NULL) {
    metadata_prop = 0;
  }
  ssize_t ret_val = getdelim(lineptr, n, delim, stream);
  if (metadata_prop) {
    __softboundmpx_read_shadow_stack_metadata_store(lineptr, 1);
  } else {
    __softboundmpx_store_return_metadata(*lineptr,
                                         (*lineptr) + strlen(*lineptr));
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<softboundmpx___getdelim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1173 <softboundmpx___getdelim+0x33>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1060 <getdelim@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11a7 <softboundmpx___getdelim+0x67>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <__softboundmpx_read_shadow_stack_metadata_store@plt>
jmp    11db <softboundmpx___getdelim+0x9b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <__softboundmpx_store_return_metadata@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<softboundmpx___getdelim>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rbp
call   1060 <getdelim@plt>
mov    %eax,%r14d
test   %rbp,%rbp
je     1166 <softboundmpx___getdelim+0x26>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <__softboundmpx_read_shadow_stack_metadata_store@plt>
jmp    117f <softboundmpx___getdelim+0x3f>
mov    (%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rsi
add    %rbx,%rsi
mov    %rbx,%rdi
call   1040 <__softboundmpx_store_return_metadata@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define weak i32 @softboundmpx___getdelim(i8** %0, i64* %1, i32 %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 1, i32* %9
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 0, i32* %9
br label %15
15: ; preds = %14, %4
%16 = load i8**, i8*** %5
%17 = load i64*, i64** %6
%18 = load i32, i32* %7
%19 = load i32*, i32** %8
%20 = call i32 @getdelim(i8** %16, i64* %17, i32 %18, i32* %19)
store i32 %20, i32* %10
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = call i32 @__softboundmpx_read_shadow_stack_metadata_store(i8** %24, i32 1)
br label %37
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
%36 = call i32 @__softboundmpx_store_return_metadata(i8* %28, i8* %35)
br label %37
37: ; preds = %26, %23
%38 = load i32, i32* %10
ret i32 %38
}

LLVM IR (-O2):
define weak i32 @softboundmpx___getdelim(i8** %0, i64* %1, i32 %2, i32* %3) {
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
%7 = tail call i32 @getdelim(i8** %0, i64* %1, i32 %2, i32* %3)
br i1 %6, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @__softboundmpx_read_shadow_stack_metadata_store(i8** %0, i32 1)
br label %16
10: ; preds = %4
%11 = load i8*, i8** %0
%12 = tail call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = tail call i32 @__softboundmpx_store_return_metadata(i8* %11, i8* %14)
br label %16
16: ; preds = %10, %8
ret i32 %7
}