#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*/ memcpy(char *, char const *, int);
char *strrchr(char const *, char);
scalar_t__ xmalloc(int);
char *xstrdup(char const *);
int http_process_type(const char *hdr, void *arg) {
  char **result = (char **)arg;
  char *p;
  *result = xstrdup(hdr);
  p = strrchr(hdr, ';');
  if (p) {
    int len = p - hdr;
    *result = (char *)xmalloc(len + 1);
    memcpy(*result, hdr, len);
    (*result)[len] = '\0';
  } else
    *result = xstrdup(hdr);
  return 1;
}


x86 assembly (clang, -O0):
<http_process_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x3b,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <http_process_type+0x92>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e5 <http_process_type+0xa5>
mov    -0x8(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_process_type>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <xstrdup@plt>
mov    %rax,(%r14)
mov    %r15,%rdi
mov    $0x3b,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     118f <http_process_type+0x4f>
mov    %rax,%rbx
sub    %r15,%rbx
lea    0x1(%rbx),%edi
call   1040 <xmalloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
mov    (%r14),%rax
movslq %ebx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    119a <http_process_type+0x5a>
mov    %r15,%rdi
call   1050 <xstrdup@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @http_process_type(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %5
%10 = load i8*, i8** %3
%11 = call i8* @xstrdup(i8* %10)
%12 = load i8**, i8*** %5
store i8* %11, i8** %12
%13 = load i8*, i8** %3
%14 = call i8* @strrchr(i8* %13, i8 signext 59)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %39
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i8*, i8** %3
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
%26 = call i64 @xmalloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i8**, i8*** %5
store i8* %27, i8** %28
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i8*, i8** %3
%32 = load i32, i32* %7
%33 = call i32 @memcpy(i8* %30, i8* %31, i32 %32)
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
br label %43
39: ; preds = %2
%40 = load i8*, i8** %3
%41 = call i8* @xstrdup(i8* %40)
%42 = load i8**, i8*** %5
store i8* %41, i8** %42
br label %43
43: ; preds = %39, %17
ret i32 1
}

LLVM IR (-O2):
define i32 @http_process_type(i8* %0, i8* nocapture %1) {
%3 = bitcast i8* %1 to i8**
%4 = tail call i8* @xstrdup(i8* %0)
store i8* %4, i8** %3
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 59)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = add nsw i32 %11, 1
%13 = tail call i64 @xmalloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = tail call i32 @memcpy(i8* %14, i8* %0, i32 %11)
%16 = load i8*, i8** %3
%17 = shl i64 %10, 32
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
br label %22
20: ; preds = %2
%21 = tail call i8* @xstrdup(i8* %0)
store i8* %21, i8** %3
br label %22
22: ; preds = %20, %7
ret i32 1
}