#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 fd_info {
  int dummy;
};

/* Variables and functions */
int AF_INET;
int SOCK_DGRAM;
int real_socket(int, int, int);
int route_socket(struct fd_info *info, int domain, int type, int protocol) {
  if (domain == AF_INET && type == SOCK_DGRAM && protocol == 0)
    return real_socket(domain, type, protocol);
  else
    return -5555;
}


x86 assembly (clang, -O0):
<route_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%eax
jne    1169 <route_socket+0x59>
mov    -0x18(%rbp),%eax
mov    0x2e9f(%rip),%rcx
cmp    (%rcx),%eax
jne    1169 <route_socket+0x59>
cmpl   $0x0,-0x1c(%rbp)
jne    1169 <route_socket+0x59>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <real_socket@plt>
mov    %eax,-0x4(%rbp)
jmp    1170 <route_socket+0x60>
movl   $0xffffea4d,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<route_socket>:
mov    0x2ed1(%rip),%rax
cmp    %esi,(%rax)
jne    1135 <route_socket+0x25>
test   %ecx,%ecx
jne    1135 <route_socket+0x25>
mov    0x2eba(%rip),%rax
cmp    %edx,(%rax)
jne    1135 <route_socket+0x25>
mov    %esi,%edi
mov    %edx,%esi
xor    %edx,%edx
jmp    1030 <real_socket@plt>
mov    $0xffffea4d,%eax
ret

LLVM IR (-O0):
%struct.fd_info = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @route_socket(%struct.fd_info* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.fd_info*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.fd_info* %0, %struct.fd_info** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %7
%11 = load i32, i32* @AF_INET
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %4
%14 = load i32, i32* %8
%15 = load i32, i32* @SOCK_DGRAM
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = call i32 @real_socket(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %5
br label %26
25: ; preds = %17, %13, %4
store i32 -5555, i32* %5
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.fd_info = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @route_socket(%struct.fd_info* nocapture readnone %0, i32 %1, i32 %2, i32 %3) {
%5 = load i32, i32* @AF_INET
%6 = icmp eq i32 %5, %1
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* @SOCK_DGRAM
%9 = icmp eq i32 %8, %2
%10 = icmp eq i32 %3, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @real_socket(i32 %1, i32 %2, i32 0)
br label %14
14: ; preds = %4, %7, %12
%15 = phi i32 [ %13, %12 ], [ -5555, %7 ], [ -5555, %4 ]
ret i32 %15
}