#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 */
typedef int u_int16_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
bool get_protocol_port_str(char *buffer, u_int16_t protocol, u_int16_t port,
                           bool is_sport) {
  switch (protocol) {
  case 6:
  case 17:
    if (snprintf(buffer, 256, "-p %u --%cport %u", protocol,
                 is_sport ? 's' : 'd', port) >= 0)
      return true;
    break;
  default:
    if (snprintf(buffer, 256, "-p %d", protocol) >= 0)
      return true;
    break;
  }
  return false;
}


x86 assembly (clang, -O0):
<get_protocol_port_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x6,%eax
je     114a <get_protocol_port_str+0x3a>
jmp    1139 <get_protocol_port_str+0x29>
mov    -0x20(%rbp),%eax
sub    $0x11,%eax
jne    1197 <get_protocol_port_str+0x87>
jmp    114a <get_protocol_port_str+0x3a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%edx
mov    $0x64,%r8d
mov    $0x73,%eax
cmp    $0x0,%edx
cmovne %eax,%r8d
mov    -0x18(%rbp),%r9d
mov    $0x100,%esi
lea    0xe8a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
cmp    $0x0,%eax
jl     1192 <get_protocol_port_str+0x82>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <get_protocol_port_str+0xc2>
jmp    11cb <get_protocol_port_str+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x100,%esi
lea    0xe68(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
cmp    $0x0,%eax
jl     11c6 <get_protocol_port_str+0xb6>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <get_protocol_port_str+0xc2>
jmp    11cb <get_protocol_port_str+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_protocol_port_str>:
push   %rax
mov    %ecx,%eax
mov    %edx,%r9d
mov    %esi,%ecx
cmp    $0x11,%esi
je     1122 <get_protocol_port_str+0x12>
cmp    $0x6,%ecx
jne    1148 <get_protocol_port_str+0x38>
test   %eax,%eax
mov    $0x64,%eax
mov    $0x73,%r8d
cmove  %eax,%r8d
lea    0xec6(%rip),%rdx
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    115b <get_protocol_port_str+0x4b>
lea    0xec3(%rip),%rdx
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
js     1168 <get_protocol_port_str+0x58>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"-p %u --%cport %u\00"
@.str.1 = [6 x i8] c"-p %d\00"
define i32 @get_protocol_port_str(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %7
switch i32 %10, label %23 [
i32 6, label %11
i32 17, label %11
]
11: ; preds = %4, %4
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 115, i32 100
%18 = load i32, i32* %8
%19 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %12, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %17, i32 %18)
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 1, i32* %5
br label %31
22: ; preds = %11
br label %30
23: ; preds = %4
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %24, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %5
br label %31
29: ; preds = %23
br label %30
30: ; preds = %29, %22
store i32 0, i32* %5
br label %31
31: ; preds = %30, %28, %21
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [18 x i8] c"-p %u --%cport %u\00"
@.str.1 = [6 x i8] c"-p %d\00"
define i32 @get_protocol_port_str(i8* %0, i32 %1, i32 %2, i32 %3) {
switch i32 %1, label %10 [
i32 6, label %5
i32 17, label %5
]
5: ; preds = %4, %4
%6 = icmp eq i32 %3, 0
%7 = select i1 %6, i32 100, i32 115
%8 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %7, i32 %2)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %14, label %13
10: ; preds = %4
%11 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %0, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %14, label %13
13: ; preds = %10, %5
br label %14
14: ; preds = %10, %5, %13
%15 = phi i32 [ 0, %13 ], [ 1, %5 ], [ 1, %10 ]
ret i32 %15
}