#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*/ fprintf(int /*<<< orphan*/, char *, ...);
char *get_lock_type_string(char const);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char const *);
unsigned int strtoul(char const *, int /*<<< orphan*/ *, int);
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int);
int decode_one_lockres(const char *lockres) {
  const char *type;
  int i;
  unsigned long long blkno;
  unsigned int generation;
  char blkstr[17];
  if ((strlen(lockres) + 1) != 32) {
    fprintf(stderr, "Invalid lockres id \"%s\"\n", lockres);
    return 1;
  }
  type = get_lock_type_string(lockres[0]);
  if (!type) {
    fprintf(stderr, "Invalid lockres type, '%c'\n", lockres[0]);
    return 1;
  }
  printf("Lockres:    %s\n", lockres);
  printf("Type:       %s\n", type);
  i = 1 + strlen("000000");
  memset(blkstr, 0, 17);
  memcpy(blkstr, &lockres[i], 16);
  blkno = strtoull(blkstr, NULL, 16);
  printf("Block:      %llu\n", blkno);
  i += 16;
  generation = strtoul(&lockres[i], NULL, 16);
  printf("Generation: 0x%08x\n", generation);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<decode_one_lockres>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    $0x20,%eax
je     11c8 <decode_one_lockres+0x48>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12df <decode_one_lockres+0x15f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <get_lock_type_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120d <decode_one_lockres+0x8d>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12df <decode_one_lockres+0x15f>
mov    -0x10(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe1d(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1060 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1090 <memcpy@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtoull@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_one_lockres>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    $0x1f,%eax
jne    126c <decode_one_lockres+0xdc>
movsbl (%rbx),%edi
call   1040 <get_lock_type_string@plt>
test   %rax,%rax
je     1288 <decode_one_lockres+0xf8>
mov    %rax,%r15
lea    0xe6f(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1070 <memset@plt>
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
mov    $0x10,%edx
call   10a0 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoull@plt>
lea    0xe2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    (%rbx,%rbp,1),%rdi
add    $0x11,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
lea    0xe17(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12a8 <decode_one_lockres+0x118>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a2 <decode_one_lockres+0x112>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
movsbl (%rbx),%edx
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Invalid lockres id \22%s\22\0A\00"
@.str.1 = [28 x i8] c"Invalid lockres type, '%c'\0A\00"
@.str.2 = [16 x i8] c"Lockres: %s\0A\00"
@.str.3 = [16 x i8] c"Type: %s\0A\00"
@.str.4 = [7 x i8] c"000000\00"
@.str.5 = [18 x i8] c"Block: %llu\0A\00"
@.str.6 = [20 x i8] c"Generation: 0x%08x\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @decode_one_lockres(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca [17 x i8]
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = icmp ne i32 %11, 32
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %2
br label %60
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = call i8* @get_lock_type_string(i8 signext %20)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %31, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 1, i32* %2
br label %60
31: ; preds = %17
%32 = load i8*, i8** %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%37 = add nsw i32 1, %36
store i32 %37, i32* %5
%38 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 17)
%40 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%41 = load i8*, i8** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i32 @memcpy(i8* %40, i8* %44, i32 16)
%46 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%47 = call i64 @strtoull(i8* %46, i32* null, i32 16)
store i64 %47, i64* %6
%48 = load i64, i64* %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %48)
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 16
store i32 %51, i32* %5
%52 = load i8*, i8** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = call i32 @strtoul(i8* %55, i32* null, i32 16)
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %2
br label %60
60: ; preds = %31, %24, %13
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Invalid lockres id \22%s\22\0A\00"
@.str.1 = [28 x i8] c"Invalid lockres type, '%c'\0A\00"
@.str.2 = [16 x i8] c"Lockres: %s\0A\00"
@.str.3 = [16 x i8] c"Type: %s\0A\00"
@.str.4 = [7 x i8] c"000000\00"
@.str.5 = [18 x i8] c"Block: %llu\0A\00"
@.str.6 = [20 x i8] c"Generation: 0x%08x\0A\00"
define i32 @decode_one_lockres(i8* %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 31
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %35
9: ; preds = %1
%10 = load i8, i8* %0
%11 = tail call i8* @get_lock_type_string(i8 signext %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8, i8* %0
%16 = sext i8 %15 to i32
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %35
18: ; preds = %9
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%22 = add nsw i32 %21, 1
%23 = call i32 @memset(i8* %3, i32 0, i32 17)
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = call i32 @memcpy(i8* %3, i8* %25, i32 16)
%27 = call i64 @strtoull(i8* nocapture %3, i32* null, i32 16)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 %27)
%29 = add nsw i32 %21, 17
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = call i32 @strtoul(i8* nocapture %31, i32* null, i32 16)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %32)
%34 = call i32 @putchar(i32 10)
br label %35
35: ; preds = %18, %13, %6
%36 = phi i32 [ 1, %6 ], [ 0, %18 ], [ 1, %13 ]
ret i32 %36
}