#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 */
char *b16encode(char const *, int);
int decryptRemoteBytes(char **, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ itoa(int const, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int encryptSymmetricKey(char **encrypted_key, const int pubkeyid,
                        const char *keyiv) {
  char *hexkey = b16encode(keyiv, 128 / 8 + 128 / 8);
  const char *base_url = "http://127.0.0.1/osir"
                         "/client-interface/encrypt.php";
  char *url =
      (char *)malloc(sizeof(char) * (strlen(base_url) + 2 + strlen(hexkey) +
                                     strlen("?pubid=&symkey=")));
  char pki_string[5];
  itoa(pubkeyid, pki_string, 10);
  strcpy(url, base_url);
  strcat(url, "?keyid=");
  strcat(url, pki_string);
  strcat(url, "&symkey=");
  strcat(url, hexkey);
  strcat(url, "\0");
  int ret = decryptRemoteBytes(encrypted_key, url);
  if (ret == -1) {
    fprintf(stderr,
            "Error: encryptSymmetricKey: decryptRemoteBytes failed (%s)\n",
            hexkey);
    return -1;
  }
  free(url);
  free(hexkey);
  return ret;
}


x86 assembly (clang, -O0):
<encryptSymmetricKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1070 <b16encode@plt>
mov    %rax,-0x28(%rbp)
lea    0xe44(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x48(%rbp)
lea    0xe4a(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x3d(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <itoa@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    -0x3d(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <decryptRemoteBytes@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12ad <encryptSymmetricKey+0x11d>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdaf(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <encryptSymmetricKey+0x135>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryptSymmetricKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%r14
mov    %rdx,%rdi
mov    $0x20,%esi
call   1070 <b16encode@plt>
mov    %rax,%r15
lea    0xe48(%rip),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    %ebx,%ebp
lea    0xe5e(%rip),%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0x3(%rsp),%rbp
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   10b0 <itoa@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <strcat@plt>
lea    0xe11(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <decryptRemoteBytes@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     126f <encryptSymmetricKey+0xdf>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1287 <encryptSymmetricKey+0xf7>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"http://127.0.0.1/osir/client-interface/encrypt.php\00"
@.str.1 = [16 x i8] c"?pubid=&symkey=\00"
@.str.2 = [8 x i8] c"?keyid=\00"
@.str.3 = [9 x i8] c"&symkey=\00"
@.str.4 = [2 x i8] zeroinitializer
@stderr = global i32 0
@.str.5 = [60 x i8] c"Error: encryptSymmetricKey: decryptRemoteBytes failed (%s)\0A\00"
define i32 @encryptSymmetricKey(i8** %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [5 x i8]
%12 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%13 = load i8*, i8** %7
%14 = call i8* @b16encode(i8* %13, i32 32)
store i8* %14, i8** %8
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8** %9
%15 = load i8*, i8** %9
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 2
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%22 = add nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = mul i64 1, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %10
%28 = load i32, i32* %6
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%30 = call i32 @itoa(i32 %28, i8* %29, i32 10)
%31 = load i8*, i8** %10
%32 = load i8*, i8** %9
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %10
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8*, i8** %10
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8*, i8** %10
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8*, i8** %10
%42 = load i8*, i8** %8
%43 = call i32 @strcat(i8* %41, i8* %42)
%44 = load i8*, i8** %10
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %10
%48 = call i32 @decryptRemoteBytes(i8** %46, i8* %47)
store i32 %48, i32* %12
%49 = load i32, i32* %12
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %55
51: ; preds = %3
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %8
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %53)
store i32 -1, i32* %4
br label %61
55: ; preds = %3
%56 = load i8*, i8** %10
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %12
store i32 %60, i32* %4
br label %61
61: ; preds = %55, %51
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [51 x i8] c"http://127.0.0.1/osir/client-interface/encrypt.php\00"
@.str.1 = [16 x i8] c"?pubid=&symkey=\00"
@.str.2 = [8 x i8] c"?keyid=\00"
@.str.3 = [9 x i8] c"&symkey=\00"
@.str.4 = [2 x i8] zeroinitializer
@stderr = global i32 0
@.str.5 = [60 x i8] c"Error: encryptSymmetricKey: decryptRemoteBytes failed (%s)\0A\00"
define i32 @encryptSymmetricKey(i8** %0, i32 %1, i8* %2) {
%4 = alloca [5 x i8]
%5 = tail call i8* @b16encode(i8* %2, i32 32)
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = add nsw i32 %6, 2
%8 = tail call i32 @strlen(i8* %5)
%9 = add nsw i32 %7, %8
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%15 = call i32 @itoa(i32 %1, i8* %14, i32 10)
%16 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @strcat(i8* %13, i8* %14)
%19 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @strcat(i8* %13, i8* %5)
%21 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @decryptRemoteBytes(i8** %0, i8* %13)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %30
27: ; preds = %3
%28 = call i32 @free(i8* %13)
%29 = call i32 @free(i8* %5)
br label %30
30: ; preds = %27, %24
ret i32 %22
}