#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*/ get_protocol_name(char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ string_search(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
int get_protocol(char *line, char *protocol) {
  int i, j, protocol_nr;
  char protocol_name[11] = "";
  char protocol_raw[6] = "";
  if (string_search(line, "tcp")) {
    memcpy(protocol, "tcp", 3);
  } else if (string_search(line, "udp")) {
    memcpy(protocol, "udp", 3);
  } else if (string_search(line, "icmp")) {
    memcpy(protocol, "icmp", 4);
  } else {
    for (i = 0; i < strlen(line); i++) {
      if (!strncmp(&line[i], "unknown  ", 9)) {
        i += 9;
        for (j = i; j < strlen(line); j++) {
          if (line[j] == ' ') {
            break;
          }
          strncat(protocol_raw, &line[j], 1);
        }
        protocol_nr = atoi(protocol_raw);
        get_protocol_name(protocol_name, protocol_nr);
        memcpy(protocol, protocol_name, 5);
        break;
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<get_protocol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x27(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1070 <memset@plt>
lea    -0x2d(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <string_search@plt>
cmp    $0x0,%rax
je     11e4 <get_protocol+0x64>
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x3,%edx
call   1090 <memcpy@plt>
jmp    1351 <get_protocol+0x1d1>
mov    -0x8(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1050 <string_search@plt>
cmp    $0x0,%rax
je     1218 <get_protocol+0x98>
mov    -0x10(%rbp),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x3,%edx
call   1090 <memcpy@plt>
jmp    134c <get_protocol+0x1cc>
mov    -0x8(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1050 <string_search@plt>
cmp    $0x0,%rax
je     124c <get_protocol+0xcc>
mov    -0x10(%rbp),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
jmp    1347 <get_protocol+0x1c7>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1342 <get_protocol+0x1c2>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xd8c(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    132f <get_protocol+0x1af>
mov    -0x14(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    1300 <get_protocol+0x180>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    12d9 <get_protocol+0x159>
jmp    1300 <get_protocol+0x180>
lea    -0x2d(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1080 <strncat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12a3 <get_protocol+0x123>
lea    -0x2d(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x27(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <get_protocol_name@plt>
mov    -0x10(%rbp),%rdi
lea    -0x27(%rbp),%rsi
mov    $0x5,%edx
call   1090 <memcpy@plt>
jmp    1342 <get_protocol+0x1c2>
jmp    1334 <get_protocol+0x1b4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1253 <get_protocol+0xd3>
jmp    1347 <get_protocol+0x1c7>
jmp    134c <get_protocol+0x1cc>
jmp    1351 <get_protocol+0x1d1>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_protocol>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movl   $0x0,0x17(%rsp)
movq   $0x0,0x10(%rsp)
movw   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe57(%rip),%rsi
call   1050 <string_search@plt>
test   %rax,%rax
je     11bc <get_protocol+0x4c>
lea    0xe46(%rip),%rsi
jmp    11d7 <get_protocol+0x67>
lea    0xe41(%rip),%rsi
mov    %r12,%rdi
call   1050 <string_search@plt>
test   %rax,%rax
je     11f3 <get_protocol+0x83>
lea    0xe2d(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1080 <memcpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0e(%rip),%rsi
mov    %r12,%rdi
call   1050 <string_search@plt>
test   %rax,%rax
je     1218 <get_protocol+0xa8>
lea    0xdfa(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
jmp    11df <get_protocol+0x6f>
mov    %r12,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11e4 <get_protocol+0x74>
xor    %ebx,%ebx
lea    0xde0(%rip),%r15
nopl   (%rax)
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     125a <get_protocol+0xea>
add    $0x1,%rbx
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1230 <get_protocol+0xc0>
jmp    11e4 <get_protocol+0x74>
lea    0x9(%rbx),%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebp
jge    129a <get_protocol+0x12a>
add    $0x9,%rbx
lea    0x8(%rsp),%r15
cmpb   $0x20,(%r12,%rbx,1)
je     129a <get_protocol+0x12a>
lea    (%r12,%rbx,1),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1070 <strncat@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1060 <strlen@plt>
cmp    %ebx,%eax
jg     1272 <get_protocol+0x102>
lea    0x8(%rsp),%rdi
call   1090 <atoi@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <get_protocol_name@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
jmp    11df <get_protocol+0x6f>

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

LLVM IR (-O2):
@.str = [4 x i8] c"tcp\00"
@.str.1 = [4 x i8] c"udp\00"
@.str.2 = [5 x i8] c"icmp\00"
@.str.3 = [10 x i8] c"unknown \00"
define i32 @get_protocol(i8* %0, i8* %1) {
%3 = alloca [11 x i8]
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%7 = tail call i64 @string_search(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
br label %56
11: ; preds = %2
%12 = tail call i64 @string_search(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
br label %56
16: ; preds = %11
%17 = tail call i64 @string_search(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @strlen(i8* %0)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %24, label %56
22: ; preds = %16
%23 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
br label %56
24: ; preds = %19, %51
%25 = phi i64 [ %52, %51 ], [ 0, %19 ]
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i32 @strncmp(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %51
29: ; preds = %24
%30 = trunc i64 %25 to i32
%31 = add nuw nsw i32 %30, 9
%32 = call i32 @strlen(i8* %0)
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = add nuw nsw i64 %25, 9
br label %36
36: ; preds = %34, %41
%37 = phi i64 [ %35, %34 ], [ %43, %41 ]
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 32
br i1 %40, label %47, label %41
41: ; preds = %36
%42 = call i32 @strncat(i8* %6, i8* %38, i32 1)
%43 = add nuw nsw i64 %37, 1
%44 = call i32 @strlen(i8* %0)
%45 = trunc i64 %43 to i32
%46 = icmp sgt i32 %44, %45
br i1 %46, label %36, label %47
47: ; preds = %41, %36, %29
%48 = call i32 @atoi(i8* %6)
%49 = call i32 @get_protocol_name(i8* %5, i32 %48)
%50 = call i32 @memcpy(i8* %1, i8* %5, i32 5)
br label %56
51: ; preds = %24
%52 = add nuw nsw i64 %25, 1
%53 = tail call i32 @strlen(i8* %0)
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %52, %54
br i1 %55, label %24, label %56
56: ; preds = %51, %19, %14, %47, %22, %9
ret i32 0
}