#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_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_DGRAM, type);
  if (type & SOCK_STREAM) {
    printf("stream......\n");
  }
  if (type & SOCK_DGRAM) {
    printf("dgram......\n");
  }
  return 0;
}


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    0x2e45(%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    0x2e18(%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    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0xc(%rsp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
mov    0x2e73(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e62(%rip),%rcx
mov    (%rcx),%edx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %eax,%edi
call   1050 <getsockopt@plt>
mov    (%rbx),%esi
mov    0x8(%rsp),%edx
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
mov    0x2e18(%rip),%rcx
test   %eax,(%rcx)
je     11bc <main+0x7c>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,(%rbx)
je     11cc <main+0x8c>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
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 = [14 x i8] c"stream......\0A\00"
@.str.2 = [13 x i8] c"dgram......\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_DGRAM
%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 ([14 x i8], [14 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 ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
ret i32 0
}

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
@str = [12 x i8] c"dgram......\00"
@str.3 = [13 x i8] c"stream......\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_DGRAM
%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 ([13 x i8], [13 x i8]* @str.3, 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 ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
ret i32 0
}