#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 */
#define SOCK_DGRAM 130
#define SOCK_SEQPACKET 129
#define SOCK_STREAM 128
size_t snprintf(char *, size_t, char *, ...);
size_t sock_log_type(int type, char *buf, size_t buf_len) {
  size_t ret;
  switch (type) {
  case SOCK_STREAM:
    ret = snprintf(buf, buf_len, "Stream ");
    break;
  case SOCK_DGRAM:
    ret = snprintf(buf, buf_len, "Datagram ");
    break;
  case SOCK_SEQPACKET:
    ret = snprintf(buf, buf_len, "Seqpacket ");
    break;
  default:
    ret = snprintf(buf, buf_len, "Unknown type %d ", type);
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sock_log_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     115f <sock_log_type+0x4f>
jmp    1139 <sock_log_type+0x29>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     119d <sock_log_type+0x8d>
jmp    114c <sock_log_type+0x3c>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
je     117e <sock_log_type+0x6e>
jmp    11bc <sock_log_type+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    11d9 <sock_log_type+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe7b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    11d9 <sock_log_type+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe66(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    11d9 <sock_log_type+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%ecx
lea    0xe4f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_log_type>:
cmp    $0x82,%edi
je     1133 <sock_log_type+0x23>
mov    %edi,%ecx
cmp    $0x81,%edi
je     113c <sock_log_type+0x2c>
cmp    $0x80,%ecx
jne    1153 <sock_log_type+0x43>
lea    0xecf(%rip),%rax
jmp    1143 <sock_log_type+0x33>
lea    0xece(%rip),%rax
jmp    1143 <sock_log_type+0x33>
lea    0xecf(%rip),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>
lea    0xec3(%rip),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"Stream \00"
@.str.1 = [10 x i8] c"Datagram \00"
@.str.2 = [11 x i8] c"Seqpacket \00"
@.str.3 = [17 x i8] c"Unknown type %d \00"
define i64 @sock_log_type(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32, i32* %4
switch i32 %8, label %21 [
i32 128, label %9
i32 130, label %13
i32 129, label %17
]
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %10, i64 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 %12, i64* %7
br label %26
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %14, i64 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i64 %16, i64* %7
br label %26
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i64 %20, i64* %7
br label %26
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = load i32, i32* %4
%25 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %24)
store i64 %25, i64* %7
br label %26
26: ; preds = %21, %17, %13, %9
%27 = load i64, i64* %7
ret i64 %27
}

LLVM IR (-O2):
@.str = [8 x i8] c"Stream \00"
@.str.1 = [10 x i8] c"Datagram \00"
@.str.2 = [11 x i8] c"Seqpacket \00"
@.str.3 = [17 x i8] c"Unknown type %d \00"
define i64 @sock_log_type(i32 %0, i8* %1, i64 %2) {
switch i32 %0, label %10 [
i32 128, label %4
i32 130, label %6
i32 129, label %8
]
4: ; preds = %3
%5 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
6: ; preds = %3
%7 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %12
8: ; preds = %3
%9 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %12
10: ; preds = %3
%11 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %12
12: ; preds = %10, %8, %6, %4
%13 = phi i64 [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ]
ret i64 %13
}