#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) {
  if (aip == (struct addrinfo *)0)
    return;
  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 ");
    break;
  }
  return;
}


x86 assembly (clang, -O0):
<print_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <print_type+0x1c>
jmp    11b9 <print_type+0xa9>
lea    0xedd(%rip),%rdi
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     11a8 <print_type+0x98>
mov    -0x10(%rbp),%rax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <print_type+0xa4>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <print_type+0xa4>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <print_type+0xa4>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <print_type+0xa4>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
jmp    11b9 <print_type+0xa9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_type>:
test   %rdi,%rdi
je     1145 <print_type+0x35>
push   %rbx
mov    %rdi,%rbx
lea    0xee0(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     1146 <print_type+0x36>
cltq
lea    0xefc(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rbx
jmp    1030 <printf@plt>
ret
lea    0xedb(%rip),%rdi
pop    %rbx
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@.str = [6 x i8] c"type \00"
@.str.1 = [8 x i8] c"stream \00"
@.str.2 = [10 x i8] c"datagram \00"
@.str.3 = [11 x i8] c"seqpacket \00"
@.str.4 = [5 x i8] c"raw \00"
@.str.5 = [9 x i8] c"unknown \00"
@reltable.print_type = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.print_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.print_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.print_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.print_type to i64)) to i32)]
define void @print_type(%struct.addrinfo* %0) {
%2 = icmp eq %struct.addrinfo* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add i32 %6, -128
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.print_type to i8*), i64 %11)
br label %13
13: ; preds = %3, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %3 ]
%15 = tail call i32 @printf(i8* dereferenceable(1) %14)
br label %16
16: ; preds = %13, %1
ret void
}