#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 hextoi(char);
scalar_t__ isxdigit(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
int http_split_args(char *argstr) {
  int count;
  for (count = 1; *argstr; ++argstr) {
    if (*argstr == '+') {
      *argstr = ' ';
    } else if (*argstr == '%' && isxdigit(argstr[1]) && isxdigit(argstr[2])) {
      *argstr = (hextoi(argstr[1]) << 4) | hextoi(argstr[2]);
      memmove(argstr + 1, argstr + 3, strlen(argstr + 3) + 1);
    } else if (*argstr == '&' || *argstr == '?') {
      *argstr = '\0';
      ++count;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<http_split_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1277 <http_split_args+0x137>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    117c <http_split_args+0x3c>
mov    -0x8(%rbp),%rax
movb   $0x20,(%rax)
jmp    1261 <http_split_args+0x121>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1227 <http_split_args+0xe7>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1227 <http_split_args+0xe7>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1227 <http_split_args+0xe7>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1050 <hextoi@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1050 <hextoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <memmove@plt>
jmp    125c <http_split_args+0x11c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
je     1247 <http_split_args+0x107>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3f,%eax
jne    1257 <http_split_args+0x117>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    125c <http_split_args+0x11c>
jmp    1261 <http_split_args+0x121>
jmp    1266 <http_split_args+0x126>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1153 <http_split_args+0x13>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_split_args>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0x1,%r14d
jmp    1168 <http_split_args+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x20,-0x1(%rbx)
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x25,%al
je     1190 <http_split_args+0x50>
cmp    $0x2b,%al
je     1160 <http_split_args+0x20>
test   %al,%al
je     120d <http_split_args+0xcd>
cmp    $0x3f,%al
jne    11f8 <http_split_args+0xb8>
jmp    11fc <http_split_args+0xbc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1060 <isxdigit@plt>
test   %rax,%rax
je     11f0 <http_split_args+0xb0>
movsbl 0x1(%rbx),%edi
call   1060 <isxdigit@plt>
test   %rax,%rax
je     11f0 <http_split_args+0xb0>
movsbl (%rbx),%edi
call   1050 <hextoi@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x1(%rbx),%edi
call   1050 <hextoi@plt>
or     %ebp,%eax
mov    %al,-0x1(%rbx)
lea    0x2(%rbx),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <memmove@plt>
add    $0x1,%rbx
jmp    1168 <http_split_args+0x28>
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%eax
cmp    $0x3f,%al
je     11fc <http_split_args+0xbc>
cmp    $0x26,%al
jne    1204 <http_split_args+0xc4>
movb   $0x0,-0x1(%rbx)
add    $0x1,%r14d
add    $0x1,%rbx
jmp    1168 <http_split_args+0x28>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @http_split_args(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %3
br label %4
4: ; preds = %71, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %74
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 43
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i8*, i8** %2
store i8 32, i8* %14
br label %70
15: ; preds = %8
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 37
br i1 %19, label %20, label %54
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = call i64 @isxdigit(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %54
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = load i8, i8* %28
%30 = call i64 @isxdigit(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %54
32: ; preds = %26
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = call i32 @hextoi(i8 signext %35)
%37 = shl i32 %36, 4
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = load i8, i8* %39
%41 = call i32 @hextoi(i8 signext %40)
%42 = or i32 %37, %41
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %2
store i8 %43, i8* %44
%45 = load i8*, i8** %2
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i64 3
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i64 3
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %51, 1
%53 = call i32 @memmove(i8* %46, i8* %48, i64 %52)
br label %69
54: ; preds = %26, %20, %15
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 38
br i1 %58, label %64, label %59
59: ; preds = %54
%60 = load i8*, i8** %2
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 63
br i1 %63, label %64, label %68
64: ; preds = %59, %54
%65 = load i8*, i8** %2
store i8 0, i8* %65
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %68
68: ; preds = %64, %59
br label %69
69: ; preds = %68, %32
br label %70
70: ; preds = %69, %13
br label %71
71: ; preds = %70
%72 = load i8*, i8** %2
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %2
br label %4
74: ; preds = %4
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
define i32 @http_split_args(i8* %0) {
br label %2
2: ; preds = %35, %1
%3 = phi i8* [ %0, %1 ], [ %37, %35 ]
%4 = phi i32 [ 1, %1 ], [ %36, %35 ]
%5 = load i8, i8* %3
switch i8 %5, label %31 [
i8 0, label %38
i8 43, label %6
i8 37, label %7
]
6: ; preds = %2
store i8 32, i8* %3
br label %35
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = tail call i64 @isxdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %3, i64 2
%14 = load i8, i8* %13
%15 = tail call i64 @isxdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %12
%18 = load i8, i8* %8
%19 = tail call i32 @hextoi(i8 signext %18)
%20 = shl i32 %19, 4
%21 = load i8, i8* %13
%22 = tail call i32 @hextoi(i8 signext %21)
%23 = or i32 %22, %20
%24 = trunc i32 %23 to i8
store i8 %24, i8* %3
%25 = getelementptr inbounds i8, i8* %3, i64 3
%26 = tail call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = tail call i32 @memmove(i8* %8, i8* %25, i64 %27)
br label %35
29: ; preds = %7, %12
%30 = load i8, i8* %3
br label %31
31: ; preds = %29, %2
%32 = phi i8 [ %30, %29 ], [ %5, %2 ]
switch i8 %32, label %35 [
i8 38, label %33
i8 63, label %33
]
33: ; preds = %31, %31
store i8 0, i8* %3
%34 = add nsw i32 %4, 1
br label %35
35: ; preds = %31, %6, %33, %17
%36 = phi i32 [ %4, %6 ], [ %4, %17 ], [ %34, %33 ], [ %4, %31 ]
%37 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
38: ; preds = %2
ret i32 %4
}