#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, long);
int /*<<< orphan*/ t_error(char *);
char *get_workingdirectory(void) {
  char *bf = NULL, *pathfile = "$WorkingPath";
  long i;
  short a;
  FILE *istream;
  istream = fopen(pathfile, "r");
  if (istream) {
    i = 0;
    a = 0;
    do {
      if (i == 0) {
        bf = (char *)malloc(sizeof(char));
      } else {
        bf = (char *)realloc(bf, (i + 1) * sizeof(char));
      }
      bf[i] = fgetc(istream);
      if (bf[i] == 10 || bf[i] == -1) {
        a = 1;
        bf[i] = 0;
      }
      i += 1;
    } while (a == 0);
    fclose(istream);
  } else {
    t_error(
        "You have to specify aworking directory when you run the executable");
  }
  return bf;
}


x86 assembly (clang, -O0):
<get_workingdirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1258 <get_workingdirectory+0xf8>
movq   $0x0,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <get_workingdirectory+0x66>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11df <get_workingdirectory+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
shl    $0x0,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     121f <get_workingdirectory+0xbf>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xffffffff,%eax
jne    1231 <get_workingdirectory+0xd1>
movw   $0x1,-0x1a(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movswl -0x1a(%rbp),%eax
cmp    $0x0,%eax
je     11a8 <get_workingdirectory+0x48>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1264 <get_workingdirectory+0x104>
lea    0xdb0(%rip),%rdi
call   1080 <t_error@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_workingdirectory>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11df <get_workingdirectory+0x7f>
mov    %rax,%r14
mov    $0x1,%ebx
xor    %r15d,%r15d
cmp    $0x1,%rbx
jne    11a0 <get_workingdirectory+0x40>
xchg   %ax,%ax
mov    $0x1,%edi
call   1050 <malloc@plt>
jmp    11ab <get_workingdirectory+0x4b>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <realloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%r15,%rbx,1)
cmp    $0xff,%al
je     11cf <get_workingdirectory+0x6f>
cmp    $0xa,%al
je     11cf <get_workingdirectory+0x6f>
add    $0x1,%rbx
cmp    $0x1,%rbx
jne    11a0 <get_workingdirectory+0x40>
jmp    1190 <get_workingdirectory+0x30>
movb   $0x0,-0x1(%r15,%rbx,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11ee <get_workingdirectory+0x8e>
lea    0xe29(%rip),%rdi
call   1080 <t_error@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"$WorkingPath\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [67 x i8] c"You have to specify aworking directory when you run the executable\00"
define i8* @get_workingdirectory() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i16
%5 = alloca i32*
store i8* null, i8** %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %57
10: ; preds = %0
store i64 0, i64* %3
store i16 0, i16* %4
br label %11
11: ; preds = %50, %10
%12 = load i64, i64* %3
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i64 @malloc(i32 1)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %1
br label %24
17: ; preds = %11
%18 = load i8*, i8** %1
%19 = load i64, i64* %3
%20 = add nsw i64 %19, 1
%21 = mul i64 %20, 1
%22 = call i64 @realloc(i8* %18, i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %1
br label %24
24: ; preds = %17, %14
%25 = load i32*, i32** %5
%26 = call signext i8 @fgetc(i32* %25)
%27 = load i8*, i8** %1
%28 = load i64, i64* %3
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 %26, i8* %29
%30 = load i8*, i8** %1
%31 = load i64, i64* %3
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br i1 %35, label %43, label %36
36: ; preds = %24
%37 = load i8*, i8** %1
%38 = load i64, i64* %3
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %36, %24
store i16 1, i16* %4
%44 = load i8*, i8** %1
%45 = load i64, i64* %3
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %43, %36
%48 = load i64, i64* %3
%49 = add nsw i64 %48, 1
store i64 %49, i64* %3
br label %50
50: ; preds = %47
%51 = load i16, i16* %4
%52 = sext i16 %51 to i32
%53 = icmp eq i32 %52, 0
br i1 %53, label %11, label %54
54: ; preds = %50
%55 = load i32*, i32** %5
%56 = call i32 @fclose(i32* %55)
br label %59
57: ; preds = %0
%58 = call i32 @t_error(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
%60 = load i8*, i8** %1
ret i8* %60
}

LLVM IR (-O2):
@.str = [13 x i8] c"$WorkingPath\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [67 x i8] c"You have to specify aworking directory when you run the executable\00"
define i8* @get_workingdirectory() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %23, label %3
3: ; preds = %0, %17
%4 = phi i64 [ %18, %17 ], [ 0, %0 ]
%5 = phi i8* [ %14, %17 ], [ null, %0 ]
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i64 @malloc(i32 1)
br label %12
9: ; preds = %3
%10 = add nuw nsw i64 %4, 1
%11 = tail call i64 @realloc(i8* %5, i64 %10)
br label %12
12: ; preds = %9, %7
%13 = phi i64 [ %8, %7 ], [ %11, %9 ]
%14 = inttoptr i64 %13 to i8*
%15 = tail call signext i8 @fgetc(i32* %1)
%16 = getelementptr inbounds i8, i8* %14, i64 %4
store i8 %15, i8* %16
switch i8 %15, label %17 [
i8 10, label %19
i8 -1, label %19
]
17: ; preds = %12
%18 = add nuw nsw i64 %4, 1
br label %3
19: ; preds = %12, %12
%20 = inttoptr i64 %13 to i8*
%21 = getelementptr inbounds i8, i8* %20, i64 %4
store i8 0, i8* %21
%22 = tail call i32 @fclose(i32* %1)
br label %25
23: ; preds = %0
%24 = tail call i32 @t_error(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = phi i8* [ %20, %19 ], [ null, %23 ]
ret i8* %26
}