#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 snprintf(char *, int, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int show_proto_value(char *val, char *buf, int bsize) {
  if (!val) {
    return -5;
  }
  if (!strcmp(val, "both")) {
    if (snprintf(buf, bsize, "UDP/TCP") >= bsize) {
      return -2;
    }
  } else if (!strcmp(val, "tcp")) {
    if (snprintf(buf, bsize, "TCP") >= bsize) {
      return -2;
    }
  } else if (!strcmp(val, "udp")) {
    if (snprintf(buf, bsize, "UDP") >= bsize) {
      return -2;
    }
  } else {
    if (snprintf(buf, bsize, "%s", val) >= bsize) {
      return -2;
    }
  }
  return strlen(buf);
}


x86 assembly (clang, -O0):
<show_proto_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <show_proto_value+0x2a>
movl   $0xfffffffb,-0x4(%rbp)
jmp    127b <show_proto_value+0x14b>
mov    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a2 <show_proto_value+0x72>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xe84(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    -0x1c(%rbp),%eax
jl     119d <show_proto_value+0x6d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    127b <show_proto_value+0x14b>
jmp    126f <show_proto_value+0x13f>
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ea <show_proto_value+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xe40(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    -0x1c(%rbp),%eax
jl     11e5 <show_proto_value+0xb5>
movl   $0xfffffffe,-0x4(%rbp)
jmp    127b <show_proto_value+0x14b>
jmp    126a <show_proto_value+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1232 <show_proto_value+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xe04(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    -0x1c(%rbp),%eax
jl     122d <show_proto_value+0xfd>
movl   $0xfffffffe,-0x4(%rbp)
jmp    127b <show_proto_value+0x14b>
jmp    1265 <show_proto_value+0x135>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xdd5(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
cmp    -0x1c(%rbp),%eax
jl     1260 <show_proto_value+0x130>
movl   $0xfffffffe,-0x4(%rbp)
jmp    127b <show_proto_value+0x14b>
jmp    1265 <show_proto_value+0x135>
jmp    126a <show_proto_value+0x13a>
jmp    126f <show_proto_value+0x13f>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_proto_value>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     118f <show_proto_value+0x5f>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb8(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1196 <show_proto_value+0x66>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     119f <show_proto_value+0x6f>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a8 <show_proto_value+0x78>
lea    0xe9b(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11bb <show_proto_value+0x8b>
mov    $0xfffffffb,%eax
jmp    11d2 <show_proto_value+0xa2>
lea    0xe68(%rip),%rdx
jmp    11af <show_proto_value+0x7f>
lea    0xe63(%rip),%rdx
jmp    11af <show_proto_value+0x7f>
lea    0xe66(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    %ebp,%ecx
jge    11d2 <show_proto_value+0xa2>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strlen@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"both\00"
@.str.1 = [8 x i8] c"UDP/TCP\00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [4 x i8] c"TCP\00"
@.str.4 = [4 x i8] c"udp\00"
@.str.5 = [4 x i8] c"UDP\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @show_proto_value(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %3
store i32 -5, i32* %4
br label %61
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %7
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -2, i32* %4
br label %61
22: ; preds = %15
br label %58
23: ; preds = %11
%24 = load i8*, i8** %5
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* %7
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 -2, i32* %4
br label %61
34: ; preds = %27
br label %57
35: ; preds = %23
%36 = load i8*, i8** %5
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i32, i32* %7
%42 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %40, i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* %7
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 -2, i32* %4
br label %61
46: ; preds = %39
br label %56
47: ; preds = %35
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = load i8*, i8** %5
%51 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %48, i32 %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %50)
%52 = load i32, i32* %7
%53 = icmp sge i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %47
store i32 -2, i32* %4
br label %61
55: ; preds = %47
br label %56
56: ; preds = %55, %46
br label %57
57: ; preds = %56, %34
br label %58
58: ; preds = %57, %22
%59 = load i8*, i8** %6
%60 = call i32 @strlen(i8* %59)
store i32 %60, i32* %4
br label %61
61: ; preds = %58, %54, %45, %33, %21, %10
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [5 x i8] c"both\00"
@.str.1 = [8 x i8] c"UDP/TCP\00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [4 x i8] c"TCP\00"
@.str.4 = [4 x i8] c"udp\00"
@.str.5 = [4 x i8] c"UDP\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @show_proto_value(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp slt i32 %9, %2
br i1 %10, label %26, label %28
11: ; preds = %5
%12 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp slt i32 %15, %2
br i1 %16, label %26, label %28
17: ; preds = %11
%18 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp slt i32 %21, %2
br i1 %22, label %26, label %28
23: ; preds = %17
%24 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%25 = icmp slt i32 %24, %2
br i1 %25, label %26, label %28
26: ; preds = %14, %23, %20, %8
%27 = tail call i32 @strlen(i8* %1)
br label %28
28: ; preds = %23, %20, %14, %8, %3, %26
%29 = phi i32 [ %27, %26 ], [ -5, %3 ], [ -2, %8 ], [ -2, %14 ], [ -2, %20 ], [ -2, %23 ]
ret i32 %29
}