#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 abs(int);
scalar_t__ getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void *strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
void exname(int *iunit, char *name, int *ln, long int nlen) {
  char string[3];
  char symbol[7];
  int ExtSymbol;
  char *darg;
  sprintf(string, "%02d", abs(*iunit));
  if (*iunit > 0) {
    ExtSymbol = 0;
    sprintf(symbol, "%s%s", "FOR0", string);
  } else {
    ExtSymbol = 1;
    sprintf(symbol, "%s%s", "EXT", string);
  }
  if ((darg = (char *)getenv(symbol)) != (char *)NULL) {
    unsigned int DargLen = strlen(darg);
    strncpy(name, darg, DargLen);
    *ln = DargLen;
  } else if (!ExtSymbol) {
    sprintf(name, "fort.%d", abs(*iunit));
    *ln = strlen(name);
  } else {
    *name = '\0';
    *ln = 0;
  }
}


x86 assembly (clang, -O0):
<exname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x23(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <abs@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11c5 <exname+0x75>
movl   $0x0,-0x30(%rbp)
lea    -0x2a(%rbp),%rdi
lea    -0x23(%rbp),%rcx
lea    0xe53(%rip),%rsi
lea    0xe51(%rip),%rdx
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    11e9 <exname+0x99>
movl   $0x1,-0x30(%rbp)
lea    -0x2a(%rbp),%rdi
lea    -0x23(%rbp),%rcx
lea    0xe2a(%rip),%rsi
lea    0xe2d(%rip),%rdx
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x2a(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     122a <exname+0xda>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1287 <exname+0x137>
cmpl   $0x0,-0x30(%rbp)
jne    1271 <exname+0x121>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <abs@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1282 <exname+0x132>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    1287 <exname+0x137>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exname>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rdi),%eax
mov    %eax,%edx
neg    %edx
cmovs  %eax,%edx
lea    0xe9c(%rip),%rsi
lea    0xe(%rsp),%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
cmpl   $0x0,(%r12)
jle    11d2 <exname+0x92>
lea    0xe87(%rip),%rsi
lea    0xe85(%rip),%rdx
lea    0x11(%rsp),%rbx
lea    0xe(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1207 <exname+0xc7>
mov    (%r12),%eax
mov    %eax,%edx
neg    %edx
cmovs  %eax,%edx
lea    0xe58(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
jmp    1220 <exname+0xe0>
lea    0xe2c(%rip),%rsi
lea    0xe2f(%rip),%rdx
xor    %r12d,%r12d
lea    0x11(%rsp),%rbx
lea    0xe(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
je     122f <exname+0xef>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <strncpy@plt>
mov    %r12d,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movb   $0x0,(%r15)
jmp    1220 <exname+0xe0>

LLVM IR (-O0):
@.str = [5 x i8] c"%02d\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [5 x i8] c"FOR0\00"
@.str.3 = [4 x i8] c"EXT\00"
@.str.4 = [8 x i8] c"fort.%d\00"
define void @exname(i32* %0, i8* %1, i32* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca [3 x i8]
%10 = alloca [7 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i64 %3, i64* %8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = call i32 @abs(i32 %16)
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %4
store i32 0, i32* %11
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %10, i64 0, i64 0
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %30
26: ; preds = %4
store i32 1, i32* %11
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %10, i64 0, i64 0
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %22
%31 = getelementptr inbounds [7 x i8], [7 x i8]* %10, i64 0, i64 0
%32 = call i64 @getenv(i8* %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %12
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load i8*, i8** %12
%37 = call i8* @strlen(i8* %36)
%38 = ptrtoint i8* %37 to i32
store i32 %38, i32* %13
%39 = load i8*, i8** %6
%40 = load i8*, i8** %12
%41 = load i32, i32* %13
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
%43 = load i32, i32* %13
%44 = load i32*, i32** %7
store i32 %43, i32* %44
br label %62
45: ; preds = %30
%46 = load i32, i32* %11
%47 = icmp ne i32 %46, 0
br i1 %47, label %58, label %48
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = load i32*, i32** %5
%51 = load i32, i32* %50
%52 = call i32 @abs(i32 %51)
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = load i8*, i8** %6
%55 = call i8* @strlen(i8* %54)
%56 = ptrtoint i8* %55 to i32
%57 = load i32*, i32** %7
store i32 %56, i32* %57
br label %61
58: ; preds = %45
%59 = load i8*, i8** %6
store i8 0, i8* %59
%60 = load i32*, i32** %7
store i32 0, i32* %60
br label %61
61: ; preds = %58, %48
br label %62
62: ; preds = %61, %35
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02d\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [5 x i8] c"FOR0\00"
@.str.3 = [4 x i8] c"EXT\00"
@.str.4 = [8 x i8] c"fort.%d\00"
define void @exname(i32* nocapture %0, i8* %1, i32* nocapture writeonly %2, i64 %3) {
%5 = alloca [3 x i8]
%6 = alloca [7 x i8]
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %0
%10 = tail call i32 @llvm.abs.i32(i32 %9, i1 true)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %0
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%16 = call i64 @getenv(i8* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %29, label %22
18: ; preds = %4
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%20 = call i64 @getenv(i8* %8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %36, label %22
22: ; preds = %18, %14
%23 = phi i64 [ %20, %18 ], [ %16, %14 ]
%24 = inttoptr i64 %23 to i8*
%25 = call i8* @strlen(i8* %24)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i32
%28 = call i32 @strncpy(i8* %1, i8* %24, i32 %27)
br label %37
29: ; preds = %14
%30 = load i32, i32* %0
%31 = call i32 @llvm.abs.i32(i32 %30, i1 true)
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i8* @strlen(i8* %1)
%34 = ptrtoint i8* %33 to i64
%35 = trunc i64 %34 to i32
br label %37
36: ; preds = %18
store i8 0, i8* %1
br label %37
37: ; preds = %29, %36, %22
%38 = phi i32 [ %35, %29 ], [ 0, %36 ], [ %27, %22 ]
store i32 %38, i32* %2
ret void
}