#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*/ lprintf(int, char *, char *);
int /*<<< orphan*/ strncpy(char *, unsigned char *, int);
int decode_maidenhead(unsigned char *element, int element_len) {
  char maidenhead[7];
  if (element_len > 6 || !element_len)
    return -1;
  strncpy(maidenhead, element, element_len);
  maidenhead[element_len] = 0;
  lprintf(14, "Grid ID: %s\r\n", maidenhead);
  return 0;
}


x86 assembly (clang, -O0):
<decode_maidenhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
jg     1143 <decode_maidenhead+0x23>
cmpl   $0x0,-0x14(%rbp)
jne    114f <decode_maidenhead+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <decode_maidenhead+0x64>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x1b(%rbp,%rax,1)
lea    -0x1b(%rbp),%rdx
mov    $0xe,%edi
lea    0xe88(%rip),%rsi
call   1040 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_maidenhead>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    $0xffffffff,%eax
cmp    $0x6,%esi
jg     1164 <decode_maidenhead+0x44>
test   %ebx,%ebx
je     1164 <decode_maidenhead+0x44>
mov    %rdi,%rsi
lea    0x1(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x1(%rsp,%rax,1)
lea    0xeab(%rip),%rsi
mov    $0xe,%edi
mov    %r14,%rdx
call   1040 <lprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Grid ID: %s\0D\0A\00"
define i32 @decode_maidenhead(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [7 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp sgt i32 %7, 6
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9, %2
store i32 -1, i32* %3
br label %23
13: ; preds = %9
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = call i32 @strncpy(i8* %14, i8* %15, i32 %16)
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%22 = call i32 @lprintf(i32 14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %13, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [14 x i8] c"Grid ID: %s\0D\0A\00"
define i32 @decode_maidenhead(i8* %0, i32 %1) {
%3 = alloca [7 x i8]
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 7
%6 = icmp ne i32 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = call i32 @strncpy(i8* %4, i8* %0, i32 %1)
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @lprintf(i32 14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %14
}