#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 /*<<< orphan*/ __softboundcets_abort();
int /*<<< orphan*/
__softboundcets_propagate_metadata_shadow_stack_from(int, int /*<<< orphan*/);
char *getcwd(char *, size_t);
int /*<<< orphan*/ printf(char *);
__attribute__((__weak__, __always___)) char *softboundcets_getcwd(char *buf,
                                                                  size_t size) {
  if (buf == NULL) {
    printf("This case not handled, requesting memory from system\n");
    __softboundcets_abort();
  }
  char *ret_ptr = getcwd(buf, size);
  __softboundcets_propagate_metadata_shadow_stack_from(1, 0);
  return ret_ptr;
}


x86 assembly (clang, -O0):
<softboundcets_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116e <softboundcets_getcwd+0x2e>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <__softboundcets_abort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <getcwd@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <__softboundcets_propagate_metadata_shadow_stack_from@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<softboundcets_getcwd>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1162 <softboundcets_getcwd+0x22>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <__softboundcets_abort@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <getcwd@plt>
mov    %rax,%rbx
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <__softboundcets_propagate_metadata_shadow_stack_from@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [54 x i8] c"This case not handled, requesting memory from system\0A\00"
define weak i8* @softboundcets_getcwd(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @__softboundcets_abort()
br label %11
11: ; preds = %8, %2
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i8* @getcwd(i8* %12, i64 %13)
store i8* %14, i8** %5
%15 = call i32 @__softboundcets_propagate_metadata_shadow_stack_from(i32 1, i32 0)
%16 = load i8*, i8** %5
ret i8* %16
}

LLVM IR (-O2):
@str = [53 x i8] c"This case not handled, requesting memory from system\00"
define weak i8* @softboundcets_getcwd(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @__softboundcets_abort()
br label %7
7: ; preds = %4, %2
%8 = tail call i8* @getcwd(i8* %0, i64 %1)
%9 = tail call i32 @__softboundcets_propagate_metadata_shadow_stack_from(i32 1, i32 0)
ret i8* %8
}