#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 *, char const *,
                            int, unsigned char, unsigned char, unsigned char,
                            unsigned char, unsigned char);
int xyz_to_meta(char *path, size_t len, const char *tile_dir,
                const char *xmlconfig, 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/%s/%d/%u/%u/%u/%u/%u.meta", tile_dir, xmlconfig, 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
push   %rbx
sub    $0x58,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movb   $0x7,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
movzbl -0x38(%rbp),%ecx
and    %ecx,%eax
shl    $0x3,%eax
mov    -0x30(%rbp),%ecx
movzbl -0x38(%rbp),%edx
and    %edx,%ecx
add    %ecx,%eax
mov    %al,-0x37(%rbp)
movzbl -0x38(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movzbl -0x38(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movzbl -0x31(%rbp),%eax
cmp    $0x5,%eax
jge    11b7 <xyz_to_meta+0xa7>
mov    -0x2c(%rbp),%eax
and    $0xf,%eax
shl    $0x4,%eax
mov    -0x30(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %al,%cl
movzbl -0x31(%rbp),%eax
mov    %cl,-0x36(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    1170 <xyz_to_meta+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    0x10(%rbp),%r9d
mov    -0x32(%rbp),%bl
mov    -0x33(%rbp),%r11b
mov    -0x34(%rbp),%r10b
mov    -0x35(%rbp),%al
lea    0xe20(%rip),%rdx
movzbl %bl,%ebx
mov    %ebx,(%rsp)
movzbl %r11b,%r11d
mov    %r11d,0x8(%rsp)
movzbl %r10b,%r10d
mov    %r10d,0x10(%rsp)
movzbl %al,%eax
mov    %eax,0x18(%rsp)
movzbl -0x36(%rbp),%eax
mov    %eax,0x20(%rsp)
call   1030 <snprintf@plt>
movzbl -0x37(%rbp),%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

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

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

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