#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 */
size_t get_rfc2231_values(char const *, char **, char **, char **);
int /*<<< orphan*/ hex_decode(char *, scalar_t__, char *);
char *malloc(scalar_t__);
scalar_t__ strlen(char *);
size_t get_rfc2231_filename(const char *in, char **charset, char **filename) {
  char *language = NULL, *value = NULL;
  size_t processed_length;
  processed_length = get_rfc2231_values(in, charset, &language, &value);
  if (value) {
    *filename = malloc(strlen(value) + 1);
    hex_decode(value, strlen(value), *filename);
  }
  return processed_length;
}


x86 assembly (clang, -O0):
<get_rfc2231_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <get_rfc2231_values@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cb <get_rfc2231_filename+0x8b>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1040 <hex_decode@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rfc2231_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <get_rfc2231_values@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11a9 <get_rfc2231_filename+0x69>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1040 <hex_decode@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @get_rfc2231_filename(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
store i8* null, i8** %7
store i8* null, i8** %8
%10 = load i8*, i8** %4
%11 = load i8**, i8*** %5
%12 = call i64 @get_rfc2231_values(i8* %10, i8** %11, i8** %7, i8** %8)
store i64 %12, i64* %9
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %27
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
%20 = load i8**, i8*** %6
store i8* %19, i8** %20
%21 = load i8*, i8** %8
%22 = load i8*, i8** %8
%23 = call i64 @strlen(i8* %22)
%24 = load i8**, i8*** %6
%25 = load i8*, i8** %24
%26 = call i32 @hex_decode(i8* %21, i64 %23, i8* %25)
br label %27
27: ; preds = %15, %3
%28 = load i64, i64* %9
ret i64 %28
}

LLVM IR (-O2):
define i64 @get_rfc2231_filename(i8* %0, i8** %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = call i64 @get_rfc2231_values(i8* %0, i8** %1, i8** %4, i8** %5)
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = call i64 @strlen(i8* %9)
%13 = add nsw i64 %12, 1
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %2
%15 = call i64 @strlen(i8* dereferenceable(1) %9)
%16 = call i32 @hex_decode(i8* %9, i64 %15, i8* %14)
br label %17
17: ; preds = %11, %3
ret i64 %8
}