#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 /*<<< orphan*/ snprintf(char *, size_t, char *, char const *, int,
                            unsigned char, unsigned char, unsigned char,
                            unsigned char, unsigned char);
int xyz_to_meta(char *path, size_t len, const char *dir, int x, int y, int z) {
  unsigned char i, hash[5], offset, mask;
  mask = (8) - 1;
  offset = (x & mask) * (8) + (y & mask);
  x &= ~mask;
  y &= ~mask;
  for (i = 0; i < 5; i++) {
    hash[i] = ((x & 0x0f) << 4) | (y & 0x0f);
    x >>= 4;
    y >>= 4;
  }
  snprintf(path, len, "%s/%d/%u/%u/%u/%u/%u.meta", dir, z, hash[4], hash[3],
           hash[2], hash[1], hash[0]);
  return offset;
}


x86 assembly (clang, -O0):
<xyz_to_meta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movb   $0x7,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
movzbl -0x2c(%rbp),%ecx
and    %ecx,%eax
shl    $0x3,%eax
mov    -0x20(%rbp),%ecx
movzbl -0x2c(%rbp),%edx
and    %edx,%ecx
add    %ecx,%eax
mov    %al,-0x2b(%rbp)
movzbl -0x2c(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movzbl -0x2c(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
movb   $0x0,-0x25(%rbp)
movzbl -0x25(%rbp),%eax
cmp    $0x5,%eax
jge    11b2 <xyz_to_meta+0xa2>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
shl    $0x4,%eax
mov    -0x20(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %al,%cl
movzbl -0x25(%rbp),%eax
mov    %cl,-0x2a(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x25(%rbp),%al
add    $0x1,%al
mov    %al,-0x25(%rbp)
jmp    116b <xyz_to_meta+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x26(%rbp),%r9b
mov    -0x27(%rbp),%r11b
mov    -0x28(%rbp),%r10b
mov    -0x29(%rbp),%al
lea    0xe28(%rip),%rdx
movzbl %r9b,%r9d
movzbl %r11b,%r11d
mov    %r11d,(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x8(%rsp)
movzbl %al,%eax
mov    %eax,0x10(%rsp)
movzbl -0x2a(%rbp),%eax
mov    %eax,0x18(%rsp)
call   1030 <snprintf@plt>
movzbl -0x2b(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xyz_to_meta>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9d,%r10d
mov    %ecx,%eax
mov    %rdx,%rcx
mov    %eax,%edx
and    $0x8,%edx
shl    $0x4,%edx
mov    %r8d,%r11d
and    $0x8,%r11d
or     %edx,%r11d
mov    %r8d,%r15d
shr    $0x4,%r15d
mov    %eax,%edx
and    $0xf0,%edx
and    $0xf,%r15d
or     %edx,%r15d
mov    %r8d,%ebx
shr    $0x8,%ebx
mov    %eax,%edx
shr    $0x4,%edx
and    $0xf0,%edx
and    $0xf,%ebx
or     %edx,%ebx
mov    %r8d,%ebp
shr    $0xc,%ebp
mov    %eax,%edx
shr    $0x8,%edx
and    $0xf0,%edx
and    $0xf,%ebp
or     %edx,%ebp
mov    %r8d,%r9d
shr    $0x10,%r9d
mov    %eax,%edx
shr    $0xc,%edx
and    $0xf0,%edx
and    $0xf,%r9d
or     %edx,%r9d
and    $0x7,%eax
and    $0x7,%r8d
lea    (%r8,%rax,8),%r14d
lea    0xe62(%rip),%rdx
mov    %r10d,%r8d
push   %r11
push   %r15
push   %rbx
push   %rbp
call   1030 <snprintf@plt>
add    $0x20,%rsp
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%s/%d/%u/%u/%u/%u/%u.meta\00"
define i32 @xyz_to_meta(i8* %0, i64 %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca [5 x i8]
%15 = alloca i8
%16 = alloca i8
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i8 7, i8* %16
%17 = load i32, i32* %10
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = and i32 %17, %19
%21 = mul nsw i32 %20, 8
%22 = load i32, i32* %11
%23 = load i8, i8* %16
%24 = zext i8 %23 to i32
%25 = and i32 %22, %24
%26 = add nsw i32 %21, %25
%27 = trunc i32 %26 to i8
store i8 %27, i8* %15
%28 = load i8, i8* %16
%29 = zext i8 %28 to i32
%30 = xor i32 %29, -1
%31 = load i32, i32* %10
%32 = and i32 %31, %30
store i32 %32, i32* %10
%33 = load i8, i8* %16
%34 = zext i8 %33 to i32
%35 = xor i32 %34, -1
%36 = load i32, i32* %11
%37 = and i32 %36, %35
store i32 %37, i32* %11
store i8 0, i8* %13
br label %38
38: ; preds = %57, %6
%39 = load i8, i8* %13
%40 = zext i8 %39 to i32
%41 = icmp slt i32 %40, 5
br i1 %41, label %42, label %60
42: ; preds = %38
%43 = load i32, i32* %10
%44 = and i32 %43, 15
%45 = shl i32 %44, 4
%46 = load i32, i32* %11
%47 = and i32 %46, 15
%48 = or i32 %45, %47
%49 = trunc i32 %48 to i8
%50 = load i8, i8* %13
%51 = zext i8 %50 to i64
%52 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 %51
store i8 %49, i8* %52
%53 = load i32, i32* %10
%54 = ashr i32 %53, 4
store i32 %54, i32* %10
%55 = load i32, i32* %11
%56 = ashr i32 %55, 4
store i32 %56, i32* %11
br label %57
57: ; preds = %42
%58 = load i8, i8* %13
%59 = add i8 %58, 1
store i8 %59, i8* %13
br label %38
60: ; preds = %38
%61 = load i8*, i8** %7
%62 = load i64, i64* %8
%63 = load i8*, i8** %9
%64 = load i32, i32* %12
%65 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 4
%66 = load i8, i8* %65
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 3
%68 = load i8, i8* %67
%69 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 2
%70 = load i8, i8* %69
%71 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 1
%72 = load i8, i8* %71
%73 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%74 = load i8, i8* %73
%75 = call i32 @snprintf(i8* %61, i64 %62, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %63, i32 %64, i8 zeroext %66, i8 zeroext %68, i8 zeroext %70, i8 zeroext %72, i8 zeroext %74)
%76 = load i8, i8* %15
%77 = zext i8 %76 to i32
ret i32 %77
}

LLVM IR (-O2):
@.str = [26 x i8] c"%s/%d/%u/%u/%u/%u/%u.meta\00"
define i32 @xyz_to_meta(i8* %0, i64 %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = shl i32 %3, 4
%8 = and i32 %7, 128
%9 = and i32 %4, 8
%10 = or i32 %8, %9
%11 = trunc i32 %10 to i8
%12 = lshr i32 %4, 4
%13 = and i32 %3, 240
%14 = and i32 %12, 15
%15 = or i32 %13, %14
%16 = trunc i32 %15 to i8
%17 = lshr i32 %4, 8
%18 = lshr i32 %3, 4
%19 = and i32 %18, 240
%20 = and i32 %17, 15
%21 = or i32 %19, %20
%22 = trunc i32 %21 to i8
%23 = lshr i32 %4, 12
%24 = lshr i32 %3, 8
%25 = and i32 %24, 240
%26 = and i32 %23, 15
%27 = or i32 %25, %26
%28 = trunc i32 %27 to i8
%29 = lshr i32 %4, 16
%30 = lshr i32 %3, 12
%31 = and i32 %30, 240
%32 = and i32 %29, 15
%33 = or i32 %31, %32
%34 = trunc i32 %33 to i8
%35 = shl i32 %3, 3
%36 = and i32 %35, 56
%37 = and i32 %4, 7
%38 = or i32 %36, %37
%39 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %5, i8 zeroext %34, i8 zeroext %28, i8 zeroext %22, i8 zeroext %16, i8 zeroext %11)
ret i32 %38
}