#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 atoi(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ ssh_logit(char *, char *);
char *strdup(char const *);
char *strsep(char **, char *);
int proto_spec(const char *spec) {
  char *s, *p, *q;
  int ret = 0x00;
  if (spec == NULL)
    return ret;
  q = s = strdup(spec);
  if (s == NULL)
    return ret;
  for ((p = strsep(&q, ",")); p && *p != '\0'; (p = strsep(&q, ","))) {
    switch (atoi(p)) {
    case 1:
      if (ret == 0x00)
        ret |= 0x02;
      ret |= 0x01;
      break;
    case 2:
      ret |= 0x04;
      break;
    default:
      ssh_logit("ignoring bad proto spec: '%s'.", p);
      break;
    }
  }
  free(s);
  return ret;
}


x86 assembly (clang, -O0):
<proto_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <proto_spec+0x29>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127d <proto_spec+0x12d>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a0 <proto_spec+0x50>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127d <proto_spec+0x12d>
lea    -0x28(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x2d(%rbp)
je     11d4 <proto_spec+0x84>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11e4 <proto_spec+0x94>
jmp    126e <proto_spec+0x11e>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0x1,%eax
je     1211 <proto_spec+0xc1>
jmp    1200 <proto_spec+0xb0>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1232 <proto_spec+0xe2>
jmp    1240 <proto_spec+0xf0>
cmpl   $0x0,-0x2c(%rbp)
jne    1224 <proto_spec+0xd4>
mov    -0x2c(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1250 <proto_spec+0x100>
mov    -0x2c(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x2c(%rbp)
jmp    1250 <proto_spec+0x100>
mov    -0x20(%rbp),%rsi
lea    0xdb7(%rip),%rdi
call   1040 <ssh_logit@plt>
jmp    1255 <proto_spec+0x105>
lea    -0x28(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x20(%rbp)
jmp    11b4 <proto_spec+0x64>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proto_spec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     120f <proto_spec+0xbf>
call   1070 <strdup@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     120f <proto_spec+0xbf>
mov    %rax,%r14
lea    0xe7e(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strsep@plt>
test   %rax,%rax
je     1205 <proto_spec+0xb5>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe65(%rip),%r15
mov    %rsp,%r13
lea    0xe5d(%rip),%r12
jmp    11ce <proto_spec+0x7e>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <ssh_logit@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strsep@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1207 <proto_spec+0xb7>
cmpb   $0x0,(%rbx)
je     1207 <proto_spec+0xb7>
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmp    $0x2,%eax
je     1200 <proto_spec+0xb0>
cmp    $0x1,%eax
jne    11b0 <proto_spec+0x60>
mov    %ebp,%eax
or     $0x1,%eax
test   %ebp,%ebp
mov    $0x3,%ecx
cmove  %ecx,%eax
mov    %eax,%ebp
jmp    11bb <proto_spec+0x6b>
nopl   0x0(%rax,%rax,1)
or     $0x4,%ebp
jmp    11bb <proto_spec+0x6b>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [31 x i8] c"ignoring bad proto spec: '%s'.\00"
define i32 @proto_spec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %7
store i32 %11, i32* %2
br label %56
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %4
store i8* %14, i8** %6
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %7
store i32 %18, i32* %2
br label %56
19: ; preds = %12
%20 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %5
br label %21
21: ; preds = %50, %19
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br label %29
29: ; preds = %24, %21
%30 = phi i1 [ false, %21 ], [ %28, %24 ]
br i1 %30, label %31, label %52
31: ; preds = %29
%32 = load i8*, i8** %5
%33 = call i32 @atoi(i8* %32)
switch i32 %33, label %46 [
i32 1, label %34
i32 2, label %43
]
34: ; preds = %31
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %7
%39 = or i32 %38, 2
store i32 %39, i32* %7
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %7
%42 = or i32 %41, 1
store i32 %42, i32* %7
br label %49
43: ; preds = %31
%44 = load i32, i32* %7
%45 = or i32 %44, 4
store i32 %45, i32* %7
br label %49
46: ; preds = %31
%47 = load i8*, i8** %5
%48 = call i32 @ssh_logit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %43, %40
br label %50
50: ; preds = %49
%51 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %51, i8** %5
br label %21
52: ; preds = %29
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %7
store i32 %55, i32* %2
br label %56
56: ; preds = %52, %17, %10
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [31 x i8] c"ignoring bad proto spec: '%s'.\00"
define i32 @proto_spec(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %33, label %5
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
store i8* %6, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %33, label %8
8: ; preds = %5
%9 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %30, label %11
11: ; preds = %8, %26
%12 = phi i32 [ %27, %26 ], [ 0, %8 ]
%13 = phi i8* [ %28, %26 ], [ %9, %8 ]
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %11
%17 = call i32 @atoi(i8* %13)
switch i32 %17, label %24 [
i32 1, label %18
i32 2, label %22
]
18: ; preds = %16
%19 = icmp eq i32 %12, 0
%20 = or i32 %12, 1
%21 = select i1 %19, i32 3, i32 %20
br label %26
22: ; preds = %16
%23 = or i32 %12, 4
br label %26
24: ; preds = %16
%25 = call i32 @ssh_logit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %26
26: ; preds = %18, %22, %24
%27 = phi i32 [ %12, %24 ], [ %23, %22 ], [ %21, %18 ]
%28 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %11
30: ; preds = %11, %26, %8
%31 = phi i32 [ 0, %8 ], [ %27, %26 ], [ %12, %11 ]
%32 = call i32 @free(i8* %6)
br label %33
33: ; preds = %5, %1, %30
%34 = phi i32 [ %31, %30 ], [ 0, %1 ], [ 0, %5 ]
ret i32 %34
}