#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_hint;

/* Variables and functions */
long long currtime_usec();
int errno;
int /*<<< orphan*/ getpid();
long long random();
int snprintf(char *, int, char *, char *, long long, long long);
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
char *strrchr(char *, char);
int make_mastershm_prefix(char *masterlog_abs, char *prefix, int size) {
  long long r;
  long long usec;
  char path_hint[16];
  int i;
  int ret;
  char *bp, *cp;
  srandom(getpid());
  r = random();
  usec = currtime_usec();
  for (i = 0; i < sizeof(path_hint) - 1; i++) {
    path_hint[i] = '_';
  }
  path_hint[i] = '\0';
  bp = masterlog_abs;
  cp = strrchr(masterlog_abs, '/');
  if (cp != NULL) {
    cp--;
  }
  for (i = sizeof(path_hint) - 2; i >= 0 && cp >= bp; i--, cp--) {
    if (*cp == '/') {
      continue;
    }
    path_hint[i] = *cp;
  }
  ret = snprintf(prefix, size, "/%s-%lld-%lld", path_hint, usec, r);
  if (ret < 0 || ret >= size) {
    do {
      errno = errno < 0 ? errno
                        : (-1 * ((((4) * 10000 + (1054))) * 1000 + (errno)));
    } while (0);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_mastershm_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
mov    $0x0,%al
call   1080 <random@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <currtime_usec@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    $0xf,%rax
jae    11c3 <make_mastershm_prefix+0x63>
movslq -0x44(%rbp),%rax
movb   $0x5f,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    119e <make_mastershm_prefix+0x3e>
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     11fd <make_mastershm_prefix+0x9d>
mov    -0x58(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
movl   $0xe,-0x44(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x44(%rbp)
mov    %al,-0x59(%rbp)
jl     1221 <make_mastershm_prefix+0xc1>
mov    -0x58(%rbp),%rax
cmp    -0x50(%rbp),%rax
setae  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    1231 <make_mastershm_prefix+0xd1>
jmp    126e <make_mastershm_prefix+0x10e>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1246 <make_mastershm_prefix+0xe6>
jmp    1254 <make_mastershm_prefix+0xf4>
mov    -0x58(%rbp),%rax
mov    (%rax),%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
mov    -0x58(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
jmp    1204 <make_mastershm_prefix+0xa4>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xd78(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     12a6 <make_mastershm_prefix+0x146>
mov    -0x48(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     12fb <make_mastershm_prefix+0x19b>
jmp    12ab <make_mastershm_prefix+0x14b>
mov    0x2d2e(%rip),%rax
cmpl   $0x0,(%rax)
jge    12cc <make_mastershm_prefix+0x16c>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
jmp    12e3 <make_mastershm_prefix+0x183>
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
add    $0x2726f30,%eax
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%ecx
mov    0x2cf3(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1302 <make_mastershm_prefix+0x1a2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_mastershm_prefix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
xor    %eax,%eax
call   1080 <random@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <currtime_usec@plt>
mov    %rax,%rbp
movabs $0x5f5f5f5f5f5f5f5f,%rax
5f 5f 5f
mov    %rax,(%rsp)
mov    %rax,0x7(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
lea    -0x1(%rax),%rcx
test   %rax,%rax
cmove  %rax,%rcx
cmp    %r14,%rcx
jb     1200 <make_mastershm_prefix+0xa0>
lea    -0x1(%rcx),%rax
xor    %edx,%edx
nopl   0x0(%rax)
movzbl (%rcx,%rdx,1),%ebx
cmp    $0x2f,%bl
je     11ed <make_mastershm_prefix+0x8d>
mov    %bl,0xe(%rsp,%rdx,1)
cmp    $0xfffffffffffffff2,%rdx
je     1200 <make_mastershm_prefix+0xa0>
lea    (%rax,%rdx,1),%rsi
add    $0xffffffffffffffff,%rdx
cmp    %r14,%rsi
jae    11e0 <make_mastershm_prefix+0x80>
lea    0xdf9(%rip),%rdx
mov    %rsp,%rcx
mov    0x10(%rsp),%rdi
mov    %r13d,%esi
mov    %rbp,%r8
mov    %r12,%r9
call   1060 <snprintf@plt>
test   %eax,%eax
js     1226 <make_mastershm_prefix+0xc6>
cmp    %r13d,%eax
jl     1243 <make_mastershm_prefix+0xe3>
mov    0x2db3(%rip),%rax
mov    (%rax),%ecx
mov    $0xfd8d90d0,%edx
sub    %ecx,%edx
test   %ecx,%ecx
cmovs  %ecx,%edx
mov    %edx,(%rax)
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/%s-%lld-%lld\00"
@errno = global i32 0
define i32 @make_mastershm_prefix(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca [16 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%15 = call i32 (...) @getpid()
%16 = call i32 @srandom(i32 %15)
%17 = call i64 (...) @random()
store i64 %17, i64* %8
%18 = call i64 (...) @currtime_usec()
store i64 %18, i64* %9
store i32 0, i32* %11
br label %19
19: ; preds = %27, %3
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 15
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 %25
store i8 95, i8* %26
br label %27
27: ; preds = %23
%28 = load i32, i32* %11
%29 = add nsw i32 %28, 1
store i32 %29, i32* %11
br label %19
30: ; preds = %19
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %5
store i8* %34, i8** %13
%35 = load i8*, i8** %5
%36 = call i8* @strrchr(i8* %35, i8 signext 47)
store i8* %36, i8** %14
%37 = load i8*, i8** %14
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load i8*, i8** %14
%41 = getelementptr inbounds i8, i8* %40, i32 -1
store i8* %41, i8** %14
br label %42
42: ; preds = %39, %30
store i32 14, i32* %11
br label %43
43: ; preds = %64, %42
%44 = load i32, i32* %11
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i8*, i8** %14
%48 = load i8*, i8** %13
%49 = icmp uge i8* %47, %48
br label %50
50: ; preds = %46, %43
%51 = phi i1 [ false, %43 ], [ %49, %46 ]
br i1 %51, label %52, label %69
52: ; preds = %50
%53 = load i8*, i8** %14
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 47
br i1 %56, label %57, label %58
57: ; preds = %52
br label %64
58: ; preds = %52
%59 = load i8*, i8** %14
%60 = load i8, i8* %59
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 %62
store i8 %60, i8* %63
br label %64
64: ; preds = %58, %57
%65 = load i32, i32* %11
%66 = add nsw i32 %65, -1
store i32 %66, i32* %11
%67 = load i8*, i8** %14
%68 = getelementptr inbounds i8, i8* %67, i32 -1
store i8* %68, i8** %14
br label %43
69: ; preds = %50
%70 = load i8*, i8** %6
%71 = load i32, i32* %7
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%73 = load i64, i64* %9
%74 = load i64, i64* %8
%75 = call i32 @snprintf(i8* %70, i32 %71, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %72, i64 %73, i64 %74)
store i32 %75, i32* %12
%76 = load i32, i32* %12
%77 = icmp slt i32 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %69
%79 = load i32, i32* %12
%80 = load i32, i32* %7
%81 = icmp sge i32 %79, %80
br i1 %81, label %82, label %95
82: ; preds = %78, %69
br label %83
83: ; preds = %82
%84 = load i32, i32* @errno
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = load i32, i32* @errno
br label %92
88: ; preds = %83
%89 = load i32, i32* @errno
%90 = add nsw i32 41054000, %89
%91 = mul nsw i32 -1, %90
br label %92
92: ; preds = %88, %86
%93 = phi i32 [ %87, %86 ], [ %91, %88 ]
store i32 %93, i32* @errno
br label %94
94: ; preds = %92
store i32 -1, i32* %4
br label %96
95: ; preds = %78
store i32 0, i32* %4
br label %96
96: ; preds = %95, %94
%97 = load i32, i32* %4
ret i32 %97
}

LLVM IR (-O2):
@.str = [14 x i8] c"/%s-%lld-%lld\00"
@errno = global i32 0
define i32 @make_mastershm_prefix(i8* %0, i8* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @srandom(i32 %7)
%9 = tail call i64 (...) @random()
%10 = tail call i64 (...) @currtime_usec()
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
store i8 0, i8* %11
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%13 = icmp eq i8* %12, null
%14 = getelementptr inbounds i8, i8* %12, i64 -1
%15 = select i1 %13, i8* null, i8* %14
%16 = icmp ult i8* %15, %0
br i1 %16, label %30, label %17
17: ; preds = %3, %24
%18 = phi i64 [ %25, %24 ], [ 14, %3 ]
%19 = phi i8* [ %26, %24 ], [ %15, %3 ]
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %18
store i8 %20, i8* %23
br label %24
24: ; preds = %17, %22
%25 = add nsw i64 %18, -1
%26 = getelementptr inbounds i8, i8* %19, i64 -1
%27 = icmp ne i64 %18, 0
%28 = icmp uge i8* %26, %0
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %17, label %30
30: ; preds = %24, %3
%31 = call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %6, i64 %10, i64 %9)
%32 = icmp sgt i32 %31, -1
%33 = icmp slt i32 %31, %2
%34 = and i1 %32, %33
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = load i32, i32* @errno
%37 = icmp slt i32 %36, 0
%38 = sub i32 -41054000, %36
%39 = select i1 %37, i32 %36, i32 %38
store i32 %39, i32* @errno
br label %40
40: ; preds = %30, %35
%41 = phi i32 [ -1, %35 ], [ 0, %30 ]
ret i32 %41
}