#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 HEXKEYBYTES;
int /*<<< orphan*/ getpublicandprivatekey(char const *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int __getpublickey_real(const char *netname, char *publickey) {
  char lookup[3 * HEXKEYBYTES];
  char *p;
  if (publickey == NULL)
    return (0);
  if (!getpublicandprivatekey(netname, lookup))
    return (0);
  p = strchr(lookup, ':');
  if (p == NULL) {
    return (0);
  }
  *p = '\0';
  (void)strncpy(publickey, lookup, HEXKEYBYTES);
  publickey[HEXKEYBYTES] = '\0';
  return (1);
}


x86 assembly (clang, -O0):
<__getpublickey_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <__getpublickey_real+0x5f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1225 <__getpublickey_real+0xf5>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1050 <getpublicandprivatekey@plt>
cmp    $0x0,%eax
jne    11b8 <__getpublickey_real+0x88>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1225 <__getpublickey_real+0xf5>
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e8 <__getpublickey_real+0xb8>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1225 <__getpublickey_real+0xf5>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    0x2dd0(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__getpublickey_real>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e9e(%rip),%r12
mov    (%r12),%eax
lea    (%rax,%rax,2),%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %r15d,%r15d
test   %rsi,%rsi
je     11a4 <__getpublickey_real+0x74>
mov    %rsi,%r14
mov    %rbx,%rsi
call   1050 <getpublicandprivatekey@plt>
test   %eax,%eax
je     11a4 <__getpublickey_real+0x74>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a4 <__getpublickey_real+0x74>
movb   $0x0,(%rax)
mov    (%r12),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
movslq (%r12),%rax
movb   $0x0,(%r14,%rax,1)
mov    $0x1,%r15d
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@HEXKEYBYTES = global i32 0
define i32 @__getpublickey_real(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @HEXKEYBYTES
%11 = mul nsw i32 3, %10
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %9
br label %37
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @getpublicandprivatekey(i8* %19, i8* %14)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 0, i32* %3
store i32 1, i32* %9
br label %37
23: ; preds = %18
%24 = call i8* @strchr(i8* %14, i8 signext 58)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 0, i32* %3
store i32 1, i32* %9
br label %37
28: ; preds = %23
%29 = load i8*, i8** %8
store i8 0, i8* %29
%30 = load i8*, i8** %5
%31 = load i32, i32* @HEXKEYBYTES
%32 = call i32 @strncpy(i8* %30, i8* %14, i32 %31)
%33 = load i8*, i8** %5
%34 = load i32, i32* @HEXKEYBYTES
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
store i32 1, i32* %3
store i32 1, i32* %9
br label %37
37: ; preds = %28, %27, %22, %17
%38 = load i8*, i8** %6
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@HEXKEYBYTES = global i32 0
define i32 @__getpublickey_real(i8* %0, i8* %1) {
%3 = load i32, i32* @HEXKEYBYTES
%4 = mul nsw i32 %3, 3
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq i8* %1, null
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = call i32 @getpublicandprivatekey(i8* %0, i8* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = call i8* @strchr(i8* %6, i8 signext 58)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %11
store i8 0, i8* %12
%15 = load i32, i32* @HEXKEYBYTES
%16 = call i32 @strncpy(i8* %1, i8* %6, i32 %15)
%17 = load i32, i32* @HEXKEYBYTES
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %11, %8, %2, %14
%21 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 0, %8 ], [ 0, %11 ]
ret i32 %21
}