#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 */
scalar_t__ isalnum(char const);
scalar_t__ strchr(char const *, char const);
int urlcount(const char *p, const char *keep) {
  int k;
  for (k = 0; *p != 0; p++) {
    if (isalnum(*p) || *p == ' ' || (keep != 0 && strchr(keep, *p) != 0)) {
      k++;
    } else {
      k += 3;
    }
  }
  return k;
}


x86 assembly (clang, -O0):
<urlcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bf <urlcount+0x9f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    1192 <urlcount+0x72>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1192 <urlcount+0x72>
cmpq   $0x0,-0x10(%rbp)
je     11a0 <urlcount+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11a0 <urlcount+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <urlcount+0x89>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11ae <urlcount+0x8e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1137 <urlcount+0x17>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urlcount>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1190 <urlcount+0x70>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
jmp    115e <urlcount+0x3e>
mov    $0x3,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %r15d,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1192 <urlcount+0x72>
movsbl %al,%edi
call   1040 <isalnum@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    1150 <urlcount+0x30>
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
je     1150 <urlcount+0x30>
test   %r14,%r14
je     113b <urlcount+0x1b>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1150 <urlcount+0x30>
jmp    113b <urlcount+0x1b>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @urlcount(i8* nocapture %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2
%6 = icmp eq i8* %1, null
br label %7
7: ; preds = %5, %21
%8 = phi i8 [ %3, %5 ], [ %25, %21 ]
%9 = phi i32 [ 0, %5 ], [ %23, %21 ]
%10 = phi i8* [ %0, %5 ], [ %24, %21 ]
%11 = tail call i64 @isalnum(i8 signext %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 32
br i1 %15, label %21, label %16
16: ; preds = %13
br i1 %6, label %20, label %17
17: ; preds = %16
%18 = tail call i64 @strchr(i8* %1, i8 signext %14)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %16
br label %21
21: ; preds = %7, %13, %17, %20
%22 = phi i32 [ 3, %20 ], [ 1, %17 ], [ 1, %13 ], [ 1, %7 ]
%23 = add nuw nsw i32 %9, %22
%24 = getelementptr inbounds i8, i8* %10, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %7
27: ; preds = %21, %2
%28 = phi i32 [ 0, %2 ], [ %23, %21 ]
ret i32 %28
}