#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 /*<<< orphan*/ type;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int SOCK_DGRAM;
int SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_TYPE;
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int main() {
  int fd;
  int type;
  int len;
  len = sizeof(type);
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &len);
  printf("%u:%u\n", SOCK_STREAM, type);
  if (type & SOCK_STREAM) {
    printf("流\n");
  }
  if (type & SOCK_DGRAM) {
    printf("报文\n");
  }
  getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &type, &len);
  printf("缓冲大小:%u\n", type);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <getsockopt@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    0x2e10(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11c1 <main+0x91>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    0x2e05(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e4 <main+0xb4>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <getsockopt@plt>
mov    -0xc(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x4,0x4(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    0x2e76(%rip),%r15
mov    (%r15),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
mov    %ebp,%edi
call   1050 <getsockopt@plt>
mov    0x2e24(%rip),%rbx
mov    (%rbx),%esi
mov    (%rsp),%edx
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
test   %eax,(%rbx)
je     11bd <main+0x7d>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%eax
test   %eax,(%r14)
je     11ce <main+0x8e>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%esi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
mov    %ebp,%edi
call   1050 <getsockopt@plt>
mov    (%rsp),%esi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_TYPE = global i32 0
@.str = [7 x i8] c"%u:%u\0A\00"
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"\E6\B5\81\0A\00"
@.str.2 = [8 x i8] c"\E6\8A\A5\E6\96\87\0A\00"
@SO_RCVBUF = global i32 0
@.str.3 = [17 x i8] c"\E7\BC\93\E5\86\B2\E5\A4\A7\E5\B0\8F:%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %4
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_TYPE
%11 = call i32 @getsockopt(i32 %8, i32 %9, i32 %10, i32* %3, i32* %4)
%12 = load i32, i32* @SOCK_STREAM
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i32, i32* %3
%16 = load i32, i32* @SOCK_STREAM
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = load i32, i32* %3
%23 = load i32, i32* @SOCK_DGRAM
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = load i32, i32* %2
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_RCVBUF
%32 = call i32 @getsockopt(i32 %29, i32 %30, i32 %31, i32* %3, i32* %4)
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_TYPE = global i32 0
@.str = [7 x i8] c"%u:%u\0A\00"
@SOCK_STREAM = global i32 0
@SO_RCVBUF = global i32 0
@.str.3 = [17 x i8] c"\E7\BC\93\E5\86\B2\E5\A4\A7\E5\B0\8F:%u\0A\00"
@str = [7 x i8] c"\E6\8A\A5\E6\96\87\00"
@str.4 = [4 x i8] c"\E6\B5\81\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_TYPE
%10 = call i32 @getsockopt(i32 %7, i32 %8, i32 %9, i32* %1, i32* %2)
%11 = load i32, i32* @SOCK_STREAM
%12 = load i32, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %1
%15 = load i32, i32* @SOCK_STREAM
%16 = and i32 %15, %14
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0))
%20 = load i32, i32* %1
br label %21
21: ; preds = %18, %0
%22 = phi i32 [ %20, %18 ], [ %14, %0 ]
%23 = load i32, i32* @SOCK_DGRAM
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_RCVBUF
%31 = call i32 @getsockopt(i32 %7, i32 %29, i32 %30, i32* %1, i32* %2)
%32 = load i32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %32)
ret i32 0
}