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

/* Variables and functions */
int ret_code();
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *strrchr(char *, char);
int sysctlbyname(char *, char *, size_t *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/);
int sys_read_string(char *dir_name, char *file_name, char *str, int max_len) {
  char path[256], *s;
  size_t len;
  snprintf(path, sizeof(path), "%s/%s", dir_name, file_name);
  for (s = &path[0]; *s != '\0'; s++)
    if (*s == '/')
      *s = '.';
  len = max_len;
  if (sysctlbyname(&path[1], str, &len, NULL, 0) == -1)
    return ret_code();
  str[(len < max_len) ? len : max_len - 1] = 0;
  if ((s = strrchr(str, '\n')))
    *s = 0;
  return 0;
}


x86 assembly (clang, -O0):
<sys_read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x100,%esi
lea    0xe8b(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d4 <sys_read_string+0x94>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b8 <sys_read_string+0x78>
mov    -0x138(%rbp),%rax
movb   $0x2e,(%rax)
jmp    11bd <sys_read_string+0x7d>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1188 <sys_read_string+0x48>
movslq -0x24(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
lea    -0x140(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
cmp    $0xffffffff,%eax
jne    1219 <sys_read_string+0xd9>
mov    $0x0,%al
call   1030 <ret_code@plt>
mov    %eax,-0x4(%rbp)
jmp    129c <sys_read_string+0x15c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x140(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jae    124b <sys_read_string+0x10b>
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
jmp    125a <sys_read_string+0x11a>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x150(%rbp)
mov    -0x148(%rbp),%rax
mov    -0x150(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
je     1295 <sys_read_string+0x155>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_read_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0x10(%rsp),%rbp
lea    0xe9d(%rip),%rdx
mov    %rbp,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
jmp    1188 <sys_read_string+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x2e,0x0(%rbp)
add    $0x1,%rbp
movzbl 0x0(%rbp),%eax
cmp    $0x2f,%al
je     1180 <sys_read_string+0x40>
test   %al,%al
jne    1184 <sys_read_string+0x44>
movslq %r14d,%rbp
mov    %rbp,0x8(%rsp)
lea    0x11(%rsp),%rdi
xor    %r14d,%r14d
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
cmp    $0xffffffff,%eax
je     11e8 <sys_read_string+0xa8>
mov    0x8(%rsp),%rax
lea    -0x1(%rbp),%ecx
cmp    %rbp,%rax
movslq %ecx,%rcx
cmovb  %rax,%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11f2 <sys_read_string+0xb2>
movb   $0x0,(%rax)
jmp    11f2 <sys_read_string+0xb2>
xor    %eax,%eax
call   1030 <ret_code@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
define i32 @sys_read_string(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = call i32 @snprintf(i8* %13, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %17, i8** %11
br label %18
18: ; preds = %31, %4
%19 = load i8*, i8** %11
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i8*, i8** %11
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = load i8*, i8** %11
store i8 46, i8* %29
br label %30
30: ; preds = %28, %23
br label %31
31: ; preds = %30
%32 = load i8*, i8** %11
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %11
br label %18
34: ; preds = %18
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
store i64 %36, i64* %12
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 1
%38 = load i8*, i8** %8
%39 = call i32 @sysctlbyname(i8* %37, i8* %38, i64* %12, i32* null, i32 0)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 (...) @ret_code()
store i32 %42, i32* %5
br label %64
43: ; preds = %34
%44 = load i8*, i8** %8
%45 = load i64, i64* %12
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = icmp ult i64 %45, %47
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = load i64, i64* %12
br label %55
51: ; preds = %43
%52 = load i32, i32* %9
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
br label %55
55: ; preds = %51, %49
%56 = phi i64 [ %50, %49 ], [ %54, %51 ]
%57 = getelementptr inbounds i8, i8* %44, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %8
%59 = call i8* @strrchr(i8* %58, i8 signext 10)
store i8* %59, i8** %11
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = load i8*, i8** %11
store i8 0, i8* %62
br label %63
63: ; preds = %61, %55
store i32 0, i32* %5
br label %64
64: ; preds = %63, %41
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i32 @sys_read_string(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = bitcast i64* %6 to i8*
%9 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %10
10: ; preds = %14, %4
%11 = phi i8* [ %7, %4 ], [ %15, %14 ]
%12 = load i8, i8* %11
switch i8 %12, label %14 [
i8 0, label %16
i8 47, label %13
]
13: ; preds = %10
store i8 46, i8* %11
br label %14
14: ; preds = %10, %13
%15 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
16: ; preds = %10
%17 = sext i32 %3 to i64
store i64 %17, i64* %6
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 1
%19 = call i32 @sysctlbyname(i8* %18, i8* %2, i64* %6, i32* null, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (...) @ret_code()
br label %33
23: ; preds = %16
%24 = load i64, i64* %6
%25 = icmp ult i64 %24, %17
%26 = add nsw i32 %3, -1
%27 = sext i32 %26 to i64
%28 = select i1 %25, i64 %24, i64 %27
%29 = getelementptr inbounds i8, i8* %2, i64 %28
store i8 0, i8* %29
%30 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 10)
%31 = icmp eq i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %23
store i8 0, i8* %30
br label %33
33: ; preds = %23, %32, %21
%34 = phi i32 [ %22, %21 ], [ 0, %32 ], [ 0, %23 ]
ret i32 %34
}