#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 EINVAL;
int ENOMEM;
int PATH_MAX;
int s_get_own_dir(char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
int s_get_mono_font_path(char *buf, size_t bufsiz) {
  int r;
  char fontdir[PATH_MAX];
  const char *relfont = "/fonts/DroidSansMono.ttf";
  r = s_get_own_dir(fontdir, PATH_MAX);
  if (r < 0)
    return r;
  if (strlen(fontdir) + strlen(relfont) + 1 > PATH_MAX)
    return -ENOMEM;
  strcpy(fontdir + strlen(fontdir), relfont);
  if (strlen(fontdir) >= bufsiz)
    return -EINVAL;
  strcpy(buf, fontdir);
  return 0;
}


x86 assembly (clang, -O0):
<s_get_mono_font_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1050 <s_get_own_dir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a4 <s_get_mono_font_path+0x74>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1256 <s_get_mono_font_path+0x126>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    0x2e21(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jbe    11f5 <s_get_mono_font_path+0xc5>
xor    %eax,%eax
mov    0x2df4(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1256 <s_get_mono_font_path+0x126>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x18(%rbp),%rax
jb     123b <s_get_mono_font_path+0x10b>
xor    %eax,%eax
mov    0x2da6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1256 <s_get_mono_font_path+0x126>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_get_mono_font_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2ea8(%rip),%r12
mov    (%r12),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1050 <s_get_own_dir@plt>
test   %eax,%eax
js     11c3 <s_get_mono_font_path+0x93>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x19(%rax),%rcx
movslq (%r12),%rdx
cmp    %rdx,%rcx
jbe    118a <s_get_mono_font_path+0x5a>
mov    0x2e50(%rip),%rcx
jmp    11bf <s_get_mono_font_path+0x8f>
add    %rbx,%rax
lea    0xe6c(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r15,%rax
jae    11b8 <s_get_mono_font_path+0x88>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    11c3 <s_get_mono_font_path+0x93>
mov    0x2e11(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [25 x i8] c"/fonts/DroidSansMono.ttf\00"
@ENOMEM = global i32 0
@EINVAL = global i32 0
define i32 @s_get_mono_font_path(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %9
%15 = load i32, i32* @PATH_MAX
%16 = call i32 @s_get_own_dir(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i32, i32* %6
store i32 %20, i32* %3
store i32 1, i32* %10
br label %47
21: ; preds = %2
%22 = call i64 @strlen(i8* %14)
%23 = load i8*, i8** %9
%24 = call i64 @strlen(i8* %23)
%25 = add i64 %22, %24
%26 = add i64 %25, 1
%27 = load i32, i32* @PATH_MAX
%28 = sext i32 %27 to i64
%29 = icmp ugt i64 %26, %28
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = load i32, i32* @ENOMEM
%32 = sub nsw i32 0, %31
store i32 %32, i32* %3
store i32 1, i32* %10
br label %47
33: ; preds = %21
%34 = call i64 @strlen(i8* %14)
%35 = getelementptr inbounds i8, i8* %14, i64 %34
%36 = load i8*, i8** %9
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = call i64 @strlen(i8* %14)
%39 = load i64, i64* %5
%40 = icmp uge i64 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* @EINVAL
%43 = sub nsw i32 0, %42
store i32 %43, i32* %3
store i32 1, i32* %10
br label %47
44: ; preds = %33
%45 = load i8*, i8** %4
%46 = call i32 @strcpy(i8* %45, i8* %14)
store i32 0, i32* %3
store i32 1, i32* %10
br label %47
47: ; preds = %44, %41, %30, %19
%48 = load i8*, i8** %7
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [25 x i8] c"/fonts/DroidSansMono.ttf\00"
@ENOMEM = global i32 0
@EINVAL = global i32 0
define i32 @s_get_mono_font_path(i8* %0, i64 %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @s_get_own_dir(i8* %5, i32 %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = call i64 @strlen(i8* %5)
%10 = add i64 %9, 25
%11 = load i32, i32* @PATH_MAX
%12 = sext i32 %11 to i64
%13 = icmp ugt i64 %10, %12
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* @ENOMEM
%16 = sub nsw i32 0, %15
br label %27
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %5, i64 %9
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = call i64 @strlen(i8* %5)
%21 = icmp ult i64 %20, %1
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
br label %27
25: ; preds = %17
%26 = call i32 @strcpy(i8* %0, i8* %5)
br label %27
27: ; preds = %2, %25, %22, %14
%28 = phi i32 [ %16, %14 ], [ %24, %22 ], [ 0, %25 ], [ %6, %2 ]
ret i32 %28
}