#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 */
scalar_t__ strlen(char const *);
const char *rbuMainToWal(const char *zName, int flags) {
  int n = (int)strlen(zName);
  const char *z = &zName[n];
  if (flags & 0x00000040) {
    int odd = 0;
    while (1) {
      if (z[0] == 0) {
        odd = 1 - odd;
        if (odd && z[1] == 0)
          break;
      }
      z++;
    }
    z += 2;
  } else {
    while (*z == 0)
      z++;
  }
  z += (n + 8 + 1);
  return z;
}


x86 assembly (clang, -O0):
<rbuMainToWal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11b2 <rbuMainToWal+0xa2>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1190 <rbuMainToWal+0x80>
mov    $0x1,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     118b <rbuMainToWal+0x7b>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    118b <rbuMainToWal+0x7b>
jmp    11a1 <rbuMainToWal+0x91>
jmp    1190 <rbuMainToWal+0x80>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1150 <rbuMainToWal+0x40>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    11dd <rbuMainToWal+0xcd>
jmp    11b7 <rbuMainToWal+0xa7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d8 <rbuMainToWal+0xc8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11b7 <rbuMainToWal+0xa7>
jmp    11dd <rbuMainToWal+0xcd>
mov    -0x10(%rbp),%ecx
add    $0x8,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rbuMainToWal>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
shl    $0x20,%rax
test   $0x40,%bpl
jne    114f <rbuMainToWal+0x3f>
lea    (%rcx,%rbx,1),%rdx
add    $0xffffffffffffffff,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rdx),%rcx
cmpb   $0x0,0x1(%rdx)
mov    %rcx,%rdx
je     1140 <rbuMainToWal+0x30>
jmp    117f <rbuMainToWal+0x6f>
add    %rbx,%rcx
add    $0x2,%rcx
xor    %edx,%edx
jmp    1164 <rbuMainToWal+0x54>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmpb   $0x0,-0x2(%rcx)
jne    1160 <rbuMainToWal+0x50>
cmp    $0x1,%edx
mov    $0x0,%edx
je     1160 <rbuMainToWal+0x50>
mov    $0x1,%edx
cmpb   $0x0,-0x1(%rcx)
jne    1160 <rbuMainToWal+0x50>
movabs $0x900000000,%rdx
add    %rdx,%rax
sar    $0x20,%rax
add    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @rbuMainToWal(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %5
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8* %14, i8** %6
%15 = load i32, i32* %4
%16 = and i32 %15, 64
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %44
18: ; preds = %2
store i32 0, i32* %7
br label %19
19: ; preds = %18, %38
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load i32, i32* %7
%27 = sub nsw i32 1, %26
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
br label %41
37: ; preds = %30, %25
br label %38
38: ; preds = %37, %19
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %6
br label %19
41: ; preds = %36
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8* %43, i8** %6
br label %54
44: ; preds = %2
br label %45
45: ; preds = %50, %44
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
br label %45
53: ; preds = %45
br label %54
54: ; preds = %53, %41
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 8
%57 = add nsw i32 %56, 1
%58 = load i8*, i8** %6
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %6
%61 = load i8*, i8** %6
ret i8* %61
}

LLVM IR (-O2):
define i8* @rbuMainToWal(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = shl i64 %3, 32
%5 = ashr exact i64 %4, 32
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = and i32 %1, 64
%8 = icmp eq i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %2, %20
%10 = phi i8* [ %22, %20 ], [ %6, %2 ]
%11 = phi i32 [ %21, %20 ], [ 0, %2 ]
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = icmp eq i32 %11, 1
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = getelementptr inbounds i8, i8* %10, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %14, %16, %9
%21 = phi i32 [ 1, %16 ], [ 0, %14 ], [ %11, %9 ]
%22 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
23: ; preds = %16
%24 = getelementptr inbounds i8, i8* %10, i64 2
br label %30
25: ; preds = %2, %25
%26 = phi i8* [ %29, %25 ], [ %6, %2 ]
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
%29 = getelementptr inbounds i8, i8* %26, i64 1
br i1 %28, label %25, label %30
30: ; preds = %25, %23
%31 = phi i8* [ %24, %23 ], [ %26, %25 ]
%32 = add i64 %4, 38654705664
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds i8, i8* %31, i64 %33
ret i8* %34
}