#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__ ems1Starf(char *, char *, char *, char **, int *);
char *ems1_creim(char const *, int);
int /*<<< orphan*/ starFree(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void ems1_starf_(const char *envar, const char *relpath, const char *acmode,
                 char *filename, int *pathlen, int envar_len, int relpath_len,
                 int acmode_len, int filename_len) {
  int index;
  char *envar_c;
  char *relpath_c;
  char *acmode_c;
  char *pfn;
  envar_c = ems1_creim(envar, envar_len);
  relpath_c = ems1_creim(relpath, relpath_len);
  acmode_c = ems1_creim(acmode, acmode_len);
  if (ems1Starf(envar_c, relpath_c, acmode_c, &pfn, pathlen)) {
    (void)strncpy(filename, pfn, filename_len);
  } else {
    filename[0] = '\0';
  }
  for (index = strlen(filename); index < filename_len; index++) {
    filename[index] = ' ';
  }
  starFree(envar_c);
  starFree(relpath_c);
  starFree(acmode_c);
}


x86 assembly (clang, -O0):
<ems1_starf_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <ems1_creim@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1060 <ems1_creim@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x18(%rbp),%esi
call   1060 <ems1_creim@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x28(%rbp),%r8
lea    -0x50(%rbp),%rcx
call   1070 <ems1Starf@plt>
cmp    $0x0,%rax
je     11e1 <ems1_starf_+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    0x20(%rbp),%edx
call   1030 <strncpy@plt>
jmp    11e8 <ems1_starf_+0x98>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    0x20(%rbp),%eax
jge    121a <ems1_starf_+0xca>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f4 <ems1_starf_+0xa4>
mov    -0x38(%rbp),%rdi
call   1050 <starFree@plt>
mov    -0x40(%rbp),%rdi
call   1050 <starFree@plt>
mov    -0x48(%rbp),%rdi
call   1050 <starFree@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ems1_starf_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    0x48(%rsp),%r12d
mov    0x40(%rsp),%r15d
mov    %r9d,%esi
call   1070 <ems1_creim@plt>
mov    %rbx,%rdi
mov    %rax,%rbx
mov    %r15d,%esi
call   1070 <ems1_creim@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    %r12d,%esi
call   1070 <ems1_creim@plt>
mov    %rax,%r12
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %r13,%r8
call   1080 <ems1Starf@plt>
test   %rax,%rax
je     11d5 <ems1_starf_+0x75>
mov    (%rsp),%rsi
mov    %r14,%rdi
mov    0x50(%rsp),%ebp
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    11dd <ems1_starf_+0x7d>
movb   $0x0,(%r14)
mov    0x50(%rsp),%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    1207 <ems1_starf_+0xa7>
movslq %eax,%rcx
add    %rcx,%r14
not    %eax
add    %ebp,%eax
add    $0x1,%rax
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1060 <starFree@plt>
mov    %r15,%rdi
call   1060 <starFree@plt>
mov    %r12,%rdi
call   1060 <starFree@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ems1_starf_(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
store i8* %0, i8** %10
store i8* %1, i8** %11
store i8* %2, i8** %12
store i8* %3, i8** %13
store i32* %4, i32** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
%24 = load i8*, i8** %10
%25 = load i32, i32* %15
%26 = call i8* @ems1_creim(i8* %24, i32 %25)
store i8* %26, i8** %20
%27 = load i8*, i8** %11
%28 = load i32, i32* %16
%29 = call i8* @ems1_creim(i8* %27, i32 %28)
store i8* %29, i8** %21
%30 = load i8*, i8** %12
%31 = load i32, i32* %17
%32 = call i8* @ems1_creim(i8* %30, i32 %31)
store i8* %32, i8** %22
%33 = load i8*, i8** %20
%34 = load i8*, i8** %21
%35 = load i8*, i8** %22
%36 = load i32*, i32** %14
%37 = call i64 @ems1Starf(i8* %33, i8* %34, i8* %35, i8** %23, i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %9
%40 = load i8*, i8** %13
%41 = load i8*, i8** %23
%42 = load i32, i32* %18
%43 = call i32 @strncpy(i8* %40, i8* %41, i32 %42)
br label %47
44: ; preds = %9
%45 = load i8*, i8** %13
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 0, i8* %46
br label %47
47: ; preds = %44, %39
%48 = load i8*, i8** %13
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %19
br label %50
50: ; preds = %59, %47
%51 = load i32, i32* %19
%52 = load i32, i32* %18
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %62
54: ; preds = %50
%55 = load i8*, i8** %13
%56 = load i32, i32* %19
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 32, i8* %58
br label %59
59: ; preds = %54
%60 = load i32, i32* %19
%61 = add nsw i32 %60, 1
store i32 %61, i32* %19
br label %50
62: ; preds = %50
%63 = load i8*, i8** %20
%64 = call i32 @starFree(i8* %63)
%65 = load i8*, i8** %21
%66 = call i32 @starFree(i8* %65)
%67 = load i8*, i8** %22
%68 = call i32 @starFree(i8* %67)
ret void
}

LLVM IR (-O2):
define void @ems1_starf_(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i8*
%11 = bitcast i8** %10 to i8*
%12 = tail call i8* @ems1_creim(i8* %0, i32 %5)
%13 = tail call i8* @ems1_creim(i8* %1, i32 %6)
%14 = tail call i8* @ems1_creim(i8* %2, i32 %7)
%15 = call i64 @ems1Starf(i8* %12, i8* %13, i8* %14, i8** %10, i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = load i8*, i8** %10
%19 = call i32 @strncpy(i8* %3, i8* %18, i32 %8)
br label %21
20: ; preds = %9
store i8 0, i8* %3
br label %21
21: ; preds = %20, %17
%22 = call i32 @strlen(i8* %3)
%23 = icmp slt i32 %22, %8
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = sext i32 %22 to i64
%26 = getelementptr i8, i8* %3, i64 %25
%27 = xor i32 %22, -1
%28 = add i32 %27, %8
%29 = zext i32 %28 to i64
%30 = add nuw nsw i64 %29, 1
br label %31
31: ; preds = %24, %21
%32 = call i32 @starFree(i8* %12)
%33 = call i32 @starFree(i8* %13)
%34 = call i32 @starFree(i8* %14)
ret void
}