#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 */
struct addrinfo {
  int ai_socktype;
};

/* Variables and functions */
#define SOCK_DGRAM 131
#define SOCK_RAW 130
#define SOCK_SEQPACKET 129
#define SOCK_STREAM 128
int /*<<< orphan*/ printf(char *, ...);
void print_type(struct addrinfo *aip) {
  printf("  type ");
  switch (aip->ai_socktype) {
  case SOCK_STREAM:
    printf("stream");
    break;
  case SOCK_DGRAM:
    printf("datagram");
    break;
  case SOCK_SEQPACKET:
    printf("seqpacket");
    break;
  case SOCK_RAW:
    printf("raw");
    break;
  default:
    printf("unknown (%d)", aip->ai_socktype);
    break;
  }
}


x86 assembly (clang, -O0):
<print_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11a2 <print_type+0x92>
mov    -0x10(%rbp),%rax
lea    0xeb3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_type+0xa6>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_type+0xa6>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_type+0xa6>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_type+0xa6>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_type>:
push   %rbx
mov    %rdi,%rbx
lea    0xef5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%esi
lea    -0x80(%rsi),%eax
cmp    $0x3,%eax
ja     1145 <print_type+0x35>
lea    0xecd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed5(%rip),%rdi
jmp    116d <print_type+0x5d>
lea    0xeea(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
lea    0xecd(%rip),%rdi
jmp    116d <print_type+0x5d>
lea    0xece(%rip),%rdi
jmp    116d <print_type+0x5d>
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
@.str = [8 x i8] c" type \00"
@.str.1 = [7 x i8] c"stream\00"
@.str.2 = [9 x i8] c"datagram\00"
@.str.3 = [10 x i8] c"seqpacket\00"
@.str.4 = [4 x i8] c"raw\00"
@.str.5 = [13 x i8] c"unknown (%d)\00"
define void @print_type(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
store %struct.addrinfo* %0, %struct.addrinfo** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = load %struct.addrinfo*, %struct.addrinfo** %2
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 0
%6 = load i32, i32* %5
switch i32 %6, label %15 [
i32 128, label %7
i32 131, label %9
i32 129, label %11
i32 130, label %13
]
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %20
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %20
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %20
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %20
15: ; preds = %1
%16 = load %struct.addrinfo*, %struct.addrinfo** %2
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %15, %13, %11, %9, %7
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@.str = [8 x i8] c" type \00"
@.str.1 = [7 x i8] c"stream\00"
@.str.2 = [9 x i8] c"datagram\00"
@.str.3 = [10 x i8] c"seqpacket\00"
@.str.4 = [4 x i8] c"raw\00"
@.str.5 = [13 x i8] c"unknown (%d)\00"
define void @print_type(%struct.addrinfo* nocapture %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 128, label %5
i32 131, label %7
i32 129, label %9
i32 130, label %11
]
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %15
9: ; preds = %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %15
11: ; preds = %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %15
13: ; preds = %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %4)
br label %15
15: ; preds = %13, %11, %9, %7, %5
ret void
}