#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
scalar_t__ grabxorkey(char *, int, int);
int /*<<< orphan*/ perror(char *);
int urltomem(char *, char *, int /*<<< orphan*/ ***);
char *grabkey(char *url, int keylen) {
  char *keybuf;
  int outputsize;
  uint8_t **output;
  outputsize = urltomem(url, "abc", &output);
  if (keylen > outputsize) {
    perror("file too small");
    exit(1);
  }
  keybuf = (char *)grabxorkey((char *)output, outputsize, keylen);
  free(output);
  return (keybuf);
}


x86 assembly (clang, -O0):
<grabkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <urltomem@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1198 <grabkey+0x48>
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <grabxorkey@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabkey>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0xea2(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1050 <urltomem@plt>
cmp    %ebx,%eax
jl     1190 <grabkey+0x40>
mov    0x8(%rsp),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <grabxorkey@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"abc\00"
@.str.1 = [15 x i8] c"file too small\00"
define i8* @grabkey(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32**
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @urltomem(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32*** %7)
store i32 %9, i32* %6
%10 = load i32, i32* %4
%11 = load i32, i32* %6
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32**, i32*** %7
%18 = bitcast i32** %17 to i8*
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = call i64 @grabxorkey(i8* %18, i32 %19, i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i32**, i32*** %7
%24 = call i32 @free(i32** %23)
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"abc\00"
@.str.1 = [15 x i8] c"file too small\00"
define i8* @grabkey(i8* %0, i32 %1) {
%3 = alloca i32**
%4 = bitcast i32*** %3 to i8*
%5 = call i32 @urltomem(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32*** %3)
%6 = icmp slt i32 %5, %1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast i32*** %3 to i8**
%12 = load i8*, i8** %11
%13 = call i64 @grabxorkey(i8* %12, i32 %5, i32 %1)
%14 = inttoptr i64 %13 to i8*
%15 = load i32**, i32*** %3
%16 = call i32 @free(i32** %15)
ret i8* %14
}