#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 */
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ getcwd(char *, unsigned int);
int strlen(char *);
int /*<<< orphan*/ swerr1(char *, unsigned int);
int /*<<< orphan*/ swerr_SetPos(char *, int);
int os_rGetWorkingDir(char *path, unsigned int maxlen, int abort_flag) {
  errno = 0;
  if (!getcwd(path, maxlen)) {
    if (errno == ERANGE && abort_flag) {
      do {
        swerr_SetPos(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/"
            "master/unix/reuse_rgetworkingdir.c",
            39);
        swerr1("os_rGetWorkingDir: buffer is too small (size = %d)", maxlen);
      } while (0);
    }
    return -1;
  }
  return strlen(path);
}


x86 assembly (clang, -O0):
<os_rGetWorkingDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e7f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%eax
jne    11cf <os_rGetWorkingDir+0x8f>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <os_rGetWorkingDir+0x83>
cmpl   $0x0,-0x18(%rbp)
je     11c3 <os_rGetWorkingDir+0x83>
jmp    119e <os_rGetWorkingDir+0x5e>
lea    0xe5b(%rip),%rdi
mov    $0x27,%esi
call   1050 <swerr_SetPos@plt>
mov    -0x14(%rbp),%esi
lea    0xeea(%rip),%rdi
call   1060 <swerr1@plt>
jmp    11c3 <os_rGetWorkingDir+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <os_rGetWorkingDir+0x9b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_rGetWorkingDir>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    0x2e82(%rip),%r15
movq   $0x0,(%r15)
call   1040 <getcwd@plt>
test   %eax,%eax
je     1178 <os_rGetWorkingDir+0x38>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strlen@plt>
test   %r14d,%r14d
je     11ab <os_rGetWorkingDir+0x6b>
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
cmp    %rax,(%r15)
jne    11ab <os_rGetWorkingDir+0x6b>
lea    0xe6d(%rip),%rdi
mov    $0x27,%esi
call   1050 <swerr_SetPos@plt>
lea    0xeff(%rip),%rdi
mov    %ebx,%esi
call   1060 <swerr1@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/master/unix/reuse_rgetworkingdir.c\00"
@.str.1 = [51 x i8] c"os_rGetWorkingDir: buffer is too small (size = %d)\00"
define i32 @os_rGetWorkingDir(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 0, i64* @errno
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 @getcwd(i8* %8, i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %3
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
br label %20
20: ; preds = %19
%21 = call i32 @swerr_SetPos(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 39)
%22 = load i32, i32* %6
%23 = call i32 @swerr1(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20
br label %25
25: ; preds = %24, %16, %12
store i32 -1, i32* %4
br label %29
26: ; preds = %3
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %25
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/misty-fungus/ejudge-debian/refs/heads/master/unix/reuse_rgetworkingdir.c\00"
@.str.1 = [51 x i8] c"os_rGetWorkingDir: buffer is too small (size = %d)\00"
define i32 @os_rGetWorkingDir(i8* %0, i32 %1, i32 %2) {
store i64 0, i64* @errno
%4 = tail call i32 @getcwd(i8* %0, i32 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
%10 = icmp ne i32 %2, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = tail call i32 @swerr_SetPos(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 39)
%14 = tail call i32 @swerr1(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %17
15: ; preds = %3
%16 = tail call i32 @strlen(i8* %0)
br label %17
17: ; preds = %6, %12, %15
%18 = phi i32 [ %16, %15 ], [ -1, %12 ], [ -1, %6 ]
ret i32 %18
}