#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*/ getcwd(char *, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int geral_pegarPastaCorrente(char dir_base[]) {
  if (strcmp("Linux", "Linux") == 0) {
    int i = 0;
    if (readlink("/proc/self/exe", dir_base, 255) == -1)
      return 2;
    else {
      i = strlen(dir_base);
      while (dir_base[i] != '/')
        i--;
      dir_base[i] = '\0';
    }
  } else if (strcmp("Linux", "Windows") == 0) {
    if (!getcwd(dir_base, 255))
      return 2;
  }
  strcat(dir_base, "/");
  return 1;
}


x86 assembly (clang, -O0):
<geral_pegarPastaCorrente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rsi
mov    %rsi,%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e6 <geral_pegarPastaCorrente+0x96>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0xff,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
jne    11a6 <geral_pegarPastaCorrente+0x56>
movl   $0x2,-0x4(%rbp)
jmp    1247 <geral_pegarPastaCorrente+0xf7>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11d5 <geral_pegarPastaCorrente+0x85>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <geral_pegarPastaCorrente+0x62>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1230 <geral_pegarPastaCorrente+0xe0>
lea    0xe13(%rip),%rdi
lea    0xe21(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    122b <geral_pegarPastaCorrente+0xdb>
mov    -0x10(%rbp),%rdi
mov    $0xff,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%eax
jne    1226 <geral_pegarPastaCorrente+0xd6>
movl   $0x2,-0x4(%rbp)
jmp    1247 <geral_pegarPastaCorrente+0xf7>
jmp    122b <geral_pegarPastaCorrente+0xdb>
jmp    1230 <geral_pegarPastaCorrente+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1070 <strcat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geral_pegarPastaCorrente>:
push   %rbx
mov    %rdi,%rbx
lea    0xea5(%rip),%rdi
mov    %rdi,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1193 <geral_pegarPastaCorrente+0x43>
lea    0xe91(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11cd <geral_pegarPastaCorrente+0x7d>
mov    %rbx,%rdi
mov    $0xff,%esi
call   1050 <getcwd@plt>
test   %eax,%eax
jne    11cd <geral_pegarPastaCorrente+0x7d>
jmp    11e3 <geral_pegarPastaCorrente+0x93>
lea    0xe6c(%rip),%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     11e3 <geral_pegarPastaCorrente+0x93>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x1,%rax
nopl   (%rax)
cmpb   $0x2f,-0x1(%rax)
lea    -0x1(%rax),%rax
jne    11c0 <geral_pegarPastaCorrente+0x70>
movb   $0x0,(%rax)
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Linux\00"
@.str.1 = [15 x i8] c"/proc/self/exe\00"
@.str.2 = [8 x i8] c"Windows\00"
@.str.3 = [2 x i8] c"/\00"
define i32 @geral_pegarPastaCorrente(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %1
store i32 0, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 255)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 2, i32* %2
br label %45
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %23, %12
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 47
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %15
26: ; preds = %15
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %26
br label %42
32: ; preds = %1
%33 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = call i32 @getcwd(i8* %36, i32 255)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35
store i32 2, i32* %2
br label %45
40: ; preds = %35
br label %41
41: ; preds = %40, %32
br label %42
42: ; preds = %41, %31
%43 = load i8*, i8** %3
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %45
45: ; preds = %42, %39, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"Linux\00"
@.str.1 = [15 x i8] c"/proc/self/exe\00"
@.str.2 = [8 x i8] c"Windows\00"
@.str.3 = [2 x i8] c"/\00"
define i32 @geral_pegarPastaCorrente(i8* %0) {
%2 = tail call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = tail call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 255)
%6 = icmp eq i32 %5, -1
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
br label %10
10: ; preds = %10, %7
%11 = phi i64 [ %15, %10 ], [ %9, %7 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
%15 = add i64 %11, -1
br i1 %14, label %16, label %10
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %17
br label %24
18: ; preds = %1
%19 = tail call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @getcwd(i8* %0, i32 255)
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %16, %18, %21
%25 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %4, %21, %24
%27 = phi i32 [ 1, %24 ], [ 2, %21 ], [ 2, %4 ]
ret i32 %27
}