#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*/ tmp;
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ name;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *get_mapname(void) {
  FILE *f;
  static char name[512], tmp[512 + 11];
  struct stat st;
  if ((f = fopen("/etc/oss.conf", "r")) == NULL) {
    perror("/etc/oss.conf");
    goto oexit2;
  }
  while (fgets(tmp, sizeof(tmp), f) != NULL) {
    int l = strlen(tmp);
    if (l > 0 && tmp[l - 1] == '\n')
      tmp[l - 1] = '\0';
    if (strncmp(tmp, "OSSLIBDIR=", 10) == 0) {
      l = snprintf(name, sizeof(name), "%s", &tmp[10]);
      if ((l >= 512) || (l < 0)) {
        fprintf(stderr, "String in /etc/oss.conf is too long!\n");
        goto oexit;
      }
      if ((stat(name, &st) == -1) || !S_ISDIR(st.st_mode)) {
        fprintf(stderr,
                "Directory %s from /etc/oss.conf cannot "
                "be used!\n",
                name);
        goto oexit;
      }
      fclose(f);
      return name;
    }
  }
  fprintf(stderr, "OSSLIBDIR not set in /etc/oss.conf, using default "
                  "/usr/lib/oss\n");
oexit:
  fclose(f);
oexit2:
  snprintf(name, sizeof(name), "/usr/lib/oss");
  return name;
}


x86 assembly (clang, -O0):
<get_mapname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe51(%rip),%rdi
lea    0xe58(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11da <get_mapname+0x3a>
lea    0xe30(%rip),%rdi
call   10c0 <perror@plt>
jmp    1350 <get_mapname+0x1b0>
jmp    11df <get_mapname+0x3f>
mov    -0x10(%rbp),%rdx
lea    0x3096(%rip),%rdi
mov    $0x20b,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1330 <get_mapname+0x190>
lea    0x307b(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1248 <get_mapname+0xa8>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x3059(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1248 <get_mapname+0xa8>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x303c(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x3031(%rip),%rdi
lea    0xdba(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    132b <get_mapname+0x18b>
lea    0x2e0f(%rip),%rdi
mov    $0x200,%esi
lea    0xd9e(%rip),%rdx
lea    0x2ffc(%rip),%rcx
add    $0xa,%rcx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jge    12a9 <get_mapname+0x109>
cmpl   $0x0,-0x1c(%rbp)
jge    12c5 <get_mapname+0x125>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1347 <get_mapname+0x1a7>
lea    0x2db4(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     12ef <get_mapname+0x14f>
mov    -0x18(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1312 <get_mapname+0x172>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
lea    0x2d7a(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1347 <get_mapname+0x1a7>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0x2d5e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1375 <get_mapname+0x1d5>
jmp    11df <get_mapname+0x3f>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0x2d29(%rip),%rdi
mov    $0x200,%esi
lea    0xd52(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    0x2d0f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mapname>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe50(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12f6 <get_mapname+0x156>
mov    %rax,%r14
lea    0x30b1(%rip),%rbx
lea    0xe3a(%rip),%r15
jmp    11f5 <get_mapname+0x55>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1237 <get_mapname+0x97>
mov    %rbx,%rdi
mov    $0x20b,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1225 <get_mapname+0x85>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11e0 <get_mapname+0x40>
add    $0xffffffff,%eax
cmpb   $0xa,(%rax,%rbx,1)
jne    11e0 <get_mapname+0x40>
movb   $0x0,(%rax,%rbx,1)
jmp    11e0 <get_mapname+0x40>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
jmp    126f <get_mapname+0xcf>
lea    0x2e42(%rip),%rdi
lea    0xdd6(%rip),%rdx
lea    0x303e(%rip),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
cmp    $0x200,%eax
jb     12a9 <get_mapname+0x109>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x2dfb(%rip),%rdi
lea    0xe29(%rip),%rdx
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0x2de1(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x2dd0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
je     12d6 <get_mapname+0x136>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
je     12d6 <get_mapname+0x136>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1298 <get_mapname+0xf8>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
lea    0x2d93(%rip),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1276 <get_mapname+0xd6>
lea    0xd03(%rip),%rdi
call   10c0 <perror@plt>
jmp    127e <get_mapname+0xde>

LLVM IR (-O0):
%struct.stat = type { i32 }
@get_mapname.name = internal global [512 x i8] zeroinitializer
@get_mapname.tmp = internal global [523 x i8] zeroinitializer
@.str = [14 x i8] c"/etc/oss.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"OSSLIBDIR=\00"
@.str.3 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.4 = [38 x i8] c"String in /etc/oss.conf is too long!\0A\00"
@.str.5 = [49 x i8] c"Directory %s from /etc/oss.conf cannot be used!\0A\00"
@.str.6 = [64 x i8] c"OSSLIBDIR not set in /etc/oss.conf, using default /usr/lib/oss\0A\00"
@.str.7 = [13 x i8] c"/usr/lib/oss\00"
define i8* @get_mapname() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca %struct.stat
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %65
9: ; preds = %0
br label %10
10: ; preds = %58, %9
%11 = load i32*, i32** %2
%12 = call i32* @fgets(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0), i32 523, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %59
14: ; preds = %10
%15 = call i32 @strlen(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0))
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %26, %18, %14
%32 = call i64 @strncmp(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %58
34: ; preds = %31
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 10))
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp sge i32 %36, 512
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i32, i32* %4
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38, %34
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %62
44: ; preds = %38
%45 = call i32 @stat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), %struct.stat* %3)
%46 = icmp eq i32 %45, -1
br i1 %46, label %52, label %47
47: ; preds = %44
%48 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @S_ISDIR(i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %47, %44
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0))
br label %62
55: ; preds = %47
%56 = load i32*, i32** %2
%57 = call i32 @fclose(i32* %56)
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i8** %1
br label %67
58: ; preds = %31
br label %10
59: ; preds = %10
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %59, %52, %41
%63 = load i32*, i32** %2
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %62, %7
%66 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i8** %1
br label %67
67: ; preds = %65, %55
%68 = load i8*, i8** %1
ret i8* %68
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@get_mapname.name = internal global [512 x i8] zeroinitializer
@get_mapname.tmp = internal global [523 x i8] zeroinitializer
@.str = [14 x i8] c"/etc/oss.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"OSSLIBDIR=\00"
@.str.3 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.4 = [38 x i8] c"String in /etc/oss.conf is too long!\0A\00"
@.str.5 = [49 x i8] c"Directory %s from /etc/oss.conf cannot be used!\0A\00"
@.str.6 = [64 x i8] c"OSSLIBDIR not set in /etc/oss.conf, using default /usr/lib/oss\0A\00"
@.str.7 = [13 x i8] c"/usr/lib/oss\00"
define i8* @get_mapname() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %47
7: ; preds = %0, %20
%8 = tail call i32* @fgets(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0), i32 523, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %42, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0))
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = add nsw i32 %11, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %13
store i8 0, i8* %16
br label %20
20: ; preds = %19, %13, %10
%21 = tail call i64 @strncmp(i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %20
%24 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([523 x i8], [523 x i8]* @get_mapname.tmp, i64 0, i64 10))
%25 = icmp ugt i32 %24, 511
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %45
29: ; preds = %23
%30 = call i32 @stat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), %struct.stat* %1)
%31 = icmp eq i32 %30, -1
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%34 = load i32, i32* %33
%35 = tail call i32 @S_ISDIR(i32 %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32, %29
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0))
br label %45
40: ; preds = %32
%41 = tail call i32 @fclose(i32* %3)
br label %49
42: ; preds = %7
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %37, %26, %42
%46 = tail call i32 @fclose(i32* %3)
br label %47
47: ; preds = %45, %5
%48 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %49
49: ; preds = %40, %47
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @get_mapname.name, i64 0, i64 0)
}