#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*/ LOG_NOTICE;
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int);
void proto_to_string(int proto, char *retstring) {
  int rc = 0;
  switch (proto) {
  case (0):
    rc = snprintf(retstring, (16), "%s", "TCPv6");
    break;
  case (2):
    rc = snprintf(retstring, (16), "%s", "UDPv6");
    break;
  case (1):
    rc = snprintf(retstring, (16), "%s", "ICMPv6");
    break;
  case (3):
    rc = snprintf(retstring, (16), "%s", "TESTSTATE");
    break;
  default:
    rc = snprintf(retstring, (16), "%s", "UNDEFINED");
    break;
  }
  if (rc < 0 || rc >= (16)) {
    syslog(
        LOG_NOTICE,
        "ipscan: ERROR : Cannot fit protocol string into buffer, returned %d\n",
        rc);
  }
  return;
}


x86 assembly (clang, -O0):
<proto_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%rax
ja     11eb <proto_to_string+0xcb>
mov    -0x20(%rbp),%rax
lea    0xeae(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
lea    0xea5(%rip),%rdx
lea    0xea1(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    120a <proto_to_string+0xea>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
lea    0xe81(%rip),%rdx
lea    0xe83(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    120a <proto_to_string+0xea>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
lea    0xe5d(%rip),%rdx
lea    0xe65(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    120a <proto_to_string+0xea>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
lea    0xe39(%rip),%rdx
lea    0xe48(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    120a <proto_to_string+0xea>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
lea    0xe15(%rip),%rdx
lea    0xe2e(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     121e <proto_to_string+0xfe>
cmpl   $0x10,-0x14(%rbp)
jl     1236 <proto_to_string+0x116>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe09(%rip),%rsi
call   1040 <syslog@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proto_to_string>:
push   %rax
cmp    $0x3,%edi
ja     1139 <proto_to_string+0x19>
movslq %edi,%rax
lea    0xf40(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
jmp    1140 <proto_to_string+0x20>
lea    0xee0(%rip),%rcx
lea    0xeb9(%rip),%rdx
mov    %rsi,%rdi
mov    $0x10,%esi
call   1030 <snprintf@plt>
cmp    $0x10,%eax
jb     1171 <proto_to_string+0x51>
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edi
lea    0xec1(%rip),%rsi
mov    %eax,%edx
pop    %rax
jmp    1040 <syslog@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"TCPv6\00"
@.str.2 = [6 x i8] c"UDPv6\00"
@.str.3 = [7 x i8] c"ICMPv6\00"
@.str.4 = [10 x i8] c"TESTSTATE\00"
@.str.5 = [10 x i8] c"UNDEFINED\00"
@LOG_NOTICE = global i32 0
@.str.6 = [69 x i8] c"ipscan: ERROR : Cannot fit protocol string into buffer, returned %d\0A\00"
define void @proto_to_string(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%6 = load i32, i32* %3
switch i32 %6, label %19 [
i32 0, label %7
i32 2, label %10
i32 1, label %13
i32 3, label %16
]
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = call i32 @snprintf(i8* %8, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %5
br label %22
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %11, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 %12, i32* %5
br label %22
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @snprintf(i8* %14, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 %15, i32* %5
br label %22
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @snprintf(i8* %17, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 %18, i32* %5
br label %22
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32 @snprintf(i8* %20, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 %21, i32* %5
br label %22
22: ; preds = %19, %16, %13, %10, %7
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp sge i32 %26, 16
br i1 %27, label %28, label %32
28: ; preds = %25, %22
%29 = load i32, i32* @LOG_NOTICE
%30 = load i32, i32* %5
%31 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %25
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"TCPv6\00"
@.str.2 = [6 x i8] c"UDPv6\00"
@.str.3 = [7 x i8] c"ICMPv6\00"
@.str.4 = [10 x i8] c"TESTSTATE\00"
@.str.5 = [10 x i8] c"UNDEFINED\00"
@LOG_NOTICE = global i32 0
@.str.6 = [69 x i8] c"ipscan: ERROR : Cannot fit protocol string into buffer, returned %d\0A\00"
@reltable.proto_to_string = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.proto_to_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.proto_to_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.proto_to_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.proto_to_string to i64)) to i32)]
define void @proto_to_string(i32 %0, i8* %1) {
%3 = icmp ult i32 %0, 4
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = sext i32 %0 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.proto_to_string to i8*), i64 %6)
br label %8
8: ; preds = %2, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %2 ]
%10 = tail call i32 @snprintf(i8* %1, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = icmp ugt i32 %10, 15
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @LOG_NOTICE
%14 = tail call i32 @syslog(i32 %13, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %10)
br label %15
15: ; preds = %8, %12
ret void
}