#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*/ printf(char *, int, ...);
char *strdup(char const *);
int strlen(char const *);
int extract_accepted_languages(const char *headerline) {
  int cnt = 0;
  char *langarr[10] = {0};
  if (headerline == NULL || *headerline == '\0') {
  } else {
    int len = strlen(headerline);
    char *copy = strdup(headerline);
    char *tmp = copy;
    if (!len)
      goto finish;
    cnt++;
    while (cnt < 10) {
      switch (*tmp) {
      case ',':
      case '\0':
        while (*copy == ' ')
          copy++;
        langarr[cnt - 1] = copy;
        if (!*tmp)
          goto finish;
        ++cnt;
        *tmp++ = '\0';
        copy = tmp;
        break;
      default:;
      }
      ++tmp;
    }
  }
finish:
  langarr[cnt] = NULL;
  printf("found %d languages\n", cnt);
  cnt = 0;
  while (langarr[cnt]) {
    printf("  %d: '%s'\n", cnt, langarr[cnt]);
    cnt++;
  }
  return cnt;
}


x86 assembly (clang, -O0):
<extract_accepted_languages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
je     1181 <extract_accepted_languages+0x41>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1186 <extract_accepted_languages+0x46>
jmp    127d <extract_accepted_languages+0x13d>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    11b6 <extract_accepted_languages+0x76>
jmp    1282 <extract_accepted_languages+0x142>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1278 <extract_accepted_languages+0x138>
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x7c(%rbp)
test   %eax,%eax
je     11f1 <extract_accepted_languages+0xb1>
jmp    11e0 <extract_accepted_languages+0xa0>
mov    -0x7c(%rbp),%eax
sub    $0x2c,%eax
jne    1262 <extract_accepted_languages+0x122>
jmp    11f1 <extract_accepted_languages+0xb1>
jmp    11f6 <extract_accepted_languages+0xb6>
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1217 <extract_accepted_languages+0xd7>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
jmp    11f6 <extract_accepted_languages+0xb6>
mov    -0x70(%rbp),%rcx
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x78(%rbp),%rax
cmpb   $0x0,(%rax)
jne    123a <extract_accepted_languages+0xfa>
jmp    1282 <extract_accepted_languages+0x142>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x78(%rbp)
movb   $0x0,(%rax)
mov    -0x78(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    1267 <extract_accepted_languages+0x127>
jmp    1267 <extract_accepted_languages+0x127>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    11bf <extract_accepted_languages+0x7f>
jmp    127d <extract_accepted_languages+0x13d>
jmp    1282 <extract_accepted_languages+0x142>
movslq -0xc(%rbp),%rax
movq   $0x0,-0x60(%rbp,%rax,8)
mov    -0xc(%rbp),%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmpq   $0x0,-0x60(%rbp,%rax,8)
je     12df <extract_accepted_languages+0x19f>
mov    -0xc(%rbp),%esi
movslq -0xc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdx
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12a7 <extract_accepted_languages+0x167>
mov    -0xc(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_accepted_languages>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %ebx,%ebx
mov    $0x0,%ecx
test   %rdi,%rdi
je     11e7 <extract_accepted_languages+0xb7>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
mov    $0x0,%ecx
je     11e7 <extract_accepted_languages+0xb7>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strdup@plt>
mov    $0x0,%ecx
test   %ebp,%ebp
je     11e7 <extract_accepted_languages+0xb7>
mov    $0x1,%ecx
mov    %rax,%rdx
jmp    11b6 <extract_accepted_languages+0x86>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ecx
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdx
add    $0x1,%rax
cmp    $0xa,%ecx
jge    11e7 <extract_accepted_languages+0xb7>
movsbl (%rax),%esi
cmp    $0x2c,%esi
je     11c2 <extract_accepted_languages+0x92>
test   %esi,%esi
jne    11ad <extract_accepted_languages+0x7d>
add    $0xffffffffffffffff,%rdx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rdx)
lea    0x1(%rdx),%rdx
je     11d0 <extract_accepted_languages+0xa0>
movslq %ecx,%rsi
mov    %rdx,-0x8(%rsp,%rsi,8)
cmpb   $0x0,(%rax)
jne    11a0 <extract_accepted_languages+0x70>
movslq %ecx,%rsi
movq   $0x0,(%rsp,%rsi,8)
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rdx
test   %rdx,%rdx
je     123a <extract_accepted_languages+0x10a>
lea    0xe04(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1220 <extract_accepted_languages+0xf0>
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"found %d languages\0A\00"
@.str.1 = [12 x i8] c" %d: '%s'\0A\00"
define i32 @extract_accepted_languages(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [10 x i8*]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%8 = bitcast [10 x i8*]* %4 to i8*
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %1
br label %66
17: ; preds = %11
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %5
%20 = load i8*, i8** %2
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
store i8* %22, i8** %7
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %17
br label %67
26: ; preds = %17
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %29
29: ; preds = %62, %26
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 10
br i1 %31, label %32, label %65
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %61 [
i32 44, label %36
i32 0, label %36
]
36: ; preds = %32, %32
br label %37
37: ; preds = %42, %36
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 32
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %6
br label %37
45: ; preds = %37
%46 = load i8*, i8** %6
%47 = load i32, i32* %3
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %49
store i8* %46, i8** %50
%51 = load i8*, i8** %7
%52 = load i8, i8* %51
%53 = icmp ne i8 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %45
br label %67
55: ; preds = %45
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
store i8 0, i8* %58
%60 = load i8*, i8** %7
store i8* %60, i8** %6
br label %62
61: ; preds = %32
br label %62
62: ; preds = %61, %55
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %7
br label %29
65: ; preds = %29
br label %66
66: ; preds = %65, %16
br label %67
67: ; preds = %66, %54, %25
%68 = load i32, i32* %3
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %69
store i8* null, i8** %70
%71 = load i32, i32* %3
%72 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %71)
store i32 0, i32* %3
br label %73
73: ; preds = %79, %67
%74 = load i32, i32* %3
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %75
%77 = load i8*, i8** %76
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %88
79: ; preds = %73
%80 = load i32, i32* %3
%81 = load i32, i32* %3
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %82
%84 = load i8*, i8** %83
%85 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %80, i8* %84)
%86 = load i32, i32* %3
%87 = add nsw i32 %86, 1
store i32 %87, i32* %3
br label %73
88: ; preds = %73
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [20 x i8] c"found %d languages\0A\00"
@.str.1 = [12 x i8] c" %d: '%s'\0A\00"
define i32 @extract_accepted_languages(i8* %0) {
%2 = alloca [10 x i8*]
%3 = bitcast [10 x i8*]* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %39, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %39, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i8* @strdup(i8* %0)
%11 = icmp eq i32 %9, 0
br i1 %11, label %39, label %12
12: ; preds = %8, %33
%13 = phi i8* [ %37, %33 ], [ %10, %8 ]
%14 = phi i8* [ %35, %33 ], [ %10, %8 ]
%15 = phi i32 [ %34, %33 ], [ 1, %8 ]
%16 = load i8, i8* %13
%17 = sext i8 %16 to i32
switch i32 %17, label %33 [
i32 44, label %18
i32 0, label %18
]
18: ; preds = %12, %12
br label %19
19: ; preds = %18, %19
%20 = phi i8* [ %23, %19 ], [ %14, %18 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
%23 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %22, label %19, label %24
24: ; preds = %19
%25 = add nsw i32 %15, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %26
store i8* %20, i8** %27
%28 = load i8, i8* %13
%29 = icmp eq i8 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %24
%31 = add nsw i32 %15, 1
%32 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %13
br label %33
33: ; preds = %12, %30
%34 = phi i32 [ %15, %12 ], [ %31, %30 ]
%35 = phi i8* [ %14, %12 ], [ %32, %30 ]
%36 = phi i8* [ %13, %12 ], [ %32, %30 ]
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = icmp slt i32 %34, 10
br i1 %38, label %12, label %39
39: ; preds = %24, %33, %8, %5, %1
%40 = phi i32 [ 0, %1 ], [ 0, %5 ], [ 0, %8 ], [ %34, %33 ], [ %15, %24 ]
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %41
store i8* null, i8** %42
%43 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %40)
%44 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 0
%45 = load i8*, i8** %44
%46 = icmp eq i8* %45, null
br i1 %46, label %58, label %47
47: ; preds = %39, %47
%48 = phi i64 [ %52, %47 ], [ 0, %39 ]
%49 = phi i8* [ %54, %47 ], [ %45, %39 ]
%50 = trunc i64 %48 to i32
%51 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %50, i8* %49)
%52 = add nuw i64 %48, 1
%53 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %47
56: ; preds = %47
%57 = trunc i64 %52 to i32
br label %58
58: ; preds = %56, %39
%59 = phi i32 [ 0, %39 ], [ %57, %56 ]
ret i32 %59
}