#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 PATH_MAX;
int errno;
char *realpath(char *, char *);
int snprintf(char *, int, char *, char *, char *);
int get_masterlog_abs(char *basedir, char *path, int size) {
  int ret;
  char buf[PATH_MAX];
  char *base_dir;
  base_dir = realpath(basedir, buf);
  if (base_dir == NULL) {
    do {
      errno = errno < 0 ? errno
                        : (-1 * ((((4) * 10000 + (1393))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  ret = snprintf(path, size, "%s/%s", base_dir, "master-log");
  if (ret < 0 || ret >= size) {
    do {
      errno = errno < 0 ? errno
                        : (-1 * ((((4) * 10000 + (1400))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_masterlog_abs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <realpath@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d4 <get_masterlog_abs+0xb4>
jmp    1178 <get_masterlog_abs+0x58>
mov    0x2e59(%rip),%rax
cmpl   $0x0,(%rax)
jge    1199 <get_masterlog_abs+0x79>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    11b0 <get_masterlog_abs+0x90>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
add    $0x2779b68,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%ecx
mov    0x2e1e(%rip),%rax
mov    %ecx,(%rax)
jmp    11c1 <get_masterlog_abs+0xa1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    127a <get_masterlog_abs+0x15a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x38(%rbp),%rcx
lea    0xe1a(%rip),%rdx
lea    0xe19(%rip),%r8
call   1030 <snprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     120b <get_masterlog_abs+0xeb>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     126c <get_masterlog_abs+0x14c>
jmp    1210 <get_masterlog_abs+0xf0>
mov    0x2dc1(%rip),%rax
cmpl   $0x0,(%rax)
jge    1231 <get_masterlog_abs+0x111>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1248 <get_masterlog_abs+0x128>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
add    $0x277b6c0,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
mov    0x2d86(%rip),%rax
mov    %ecx,(%rax)
jmp    1259 <get_masterlog_abs+0x139>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    127a <get_masterlog_abs+0x15a>
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):
<get_masterlog_abs>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rsi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
call   1040 <realpath@plt>
test   %rax,%rax
je     1187 <get_masterlog_abs+0x67>
lea    0xea9(%rip),%rdx
lea    0xea8(%rip),%r8
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1030 <snprintf@plt>
test   %eax,%eax
js     1177 <get_masterlog_abs+0x57>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
jl     11aa <get_masterlog_abs+0x8a>
mov    0x2e5a(%rip),%rax
mov    (%rax),%ecx
mov    $0xfd884940,%eax
jmp    1195 <get_masterlog_abs+0x75>
mov    0x2e4a(%rip),%rax
mov    (%rax),%ecx
mov    $0xfd886498,%eax
sub    %ecx,%eax
test   %ecx,%ecx
cmovs  %ecx,%eax
mov    0x2e35(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@PATH_MAX = global i32 0
@errno = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [11 x i8] c"master-log\00"
define i32 @get_masterlog_abs(i8* nocapture %0, i8* %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i8* @realpath(i8* %0, i8* %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @errno
%11 = icmp slt i32 %10, 0
%12 = sub i32 -41393000, %10
%13 = select i1 %11, i32 %10, i32 %12
br label %24
14: ; preds = %3
%15 = call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp sgt i32 %15, -1
%17 = icmp slt i32 %15, %2
%18 = and i1 %16, %17
br i1 %18, label %26, label %19
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = icmp slt i32 %20, 0
%22 = sub i32 -41400000, %20
%23 = select i1 %21, i32 %20, i32 %22
br label %24
24: ; preds = %9, %19
%25 = phi i32 [ %23, %19 ], [ %13, %9 ]
store i32 %25, i32* @errno
br label %26
26: ; preds = %24, %14
%27 = phi i32 [ 0, %14 ], [ -1, %24 ]
ret i32 %27
}