#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct x25_sudirrip_struct {
  unsigned long global_facil_mask;
  int extended;
  char *device;
  int winsize_in;
  int winsize_out;
  int pacsize_in;
  int pacsize_out;
  int throughput;
  int reverse;
  int calling_len;
  int called_len;
  int /*<<< orphan*/ called_ae;
  int /*<<< orphan*/ calling_ae;
};
struct x25_facilities {
  unsigned long global_facil_mask;
  int extended;
  char *device;
  int winsize_in;
  int winsize_out;
  int pacsize_in;
  int pacsize_out;
  int throughput;
  int reverse;
  int calling_len;
  int called_len;
  int /*<<< orphan*/ called_ae;
  int /*<<< orphan*/ calling_ae;
};
struct x25_dte_facilities {
  unsigned long global_facil_mask;
  int extended;
  char *device;
  int winsize_in;
  int winsize_out;
  int pacsize_in;
  int pacsize_out;
  int throughput;
  int reverse;
  int calling_len;
  int called_len;
  int /*<<< orphan*/ called_ae;
  int /*<<< orphan*/ calling_ae;
};
struct TYPE_2__ {
  char *x25_addr;
};
struct sockaddr_x25 {
  TYPE_1__ sx25_addr;
  void *sx25_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ on;
typedef int /*<<< orphan*/ dest_addr;
typedef int /*<<< orphan*/ bind_addr;

/* Variables and functions */
void *AF_X25;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
long O_NONBLOCK;
int /*<<< orphan*/ SIOCX25SDTEFACILITIES;
int /*<<< orphan*/ SIOCX25SFACILITIES;
int /*<<< orphan*/ SIOCX25SSUBSCRIP;
int /*<<< orphan*/ SOCK_SEQPACKET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_DEBUG;
unsigned long X25_MASK_CALLED_AE;
unsigned long X25_MASK_CALLING_AE;
unsigned long X25_MASK_PACKET_SIZE;
unsigned long X25_MASK_WINDOW_SIZE;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_x25 *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
long fcntl(int, int /*<<< orphan*/, long);
char *index(char *, char);
int ioctl(int, int /*<<< orphan*/, struct x25_sudirrip_struct *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, unsigned char **, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ to_bcd(unsigned char *, char *);
int OpenX25Socket(char *local, char *remote) {
  int ret = -1;
  struct sockaddr_x25 bind_addr, dest_addr;
  bzero(&bind_addr, sizeof(bind_addr));
  bzero(&dest_addr, sizeof(dest_addr));
  bind_addr.sx25_family = AF_X25;
  dest_addr.sx25_family = AF_X25;
  char x25local[256], x25remote[256];
  strcpy(x25local, local);
  strcpy(x25remote, remote);
  char *idx;
  if ((idx = index(x25local, '-')) != NULL)
    *idx = 0;
  if ((idx = index(x25remote, '-')) != NULL)
    *idx = 0;
  strcpy(bind_addr.sx25_addr.x25_addr, x25local);
  strcpy(dest_addr.sx25_addr.x25_addr, x25remote);
  ret = socket(AF_X25, SOCK_SEQPACKET, 0);
  if (ret < 0) {
    perror("socket");
    return -1;
  }
  int on = 1;
  setsockopt(ret, SOL_SOCKET, SO_DEBUG, &on, sizeof(on));
  unsigned long facil_mask = (X25_MASK_PACKET_SIZE | X25_MASK_WINDOW_SIZE |
                              X25_MASK_CALLING_AE | X25_MASK_CALLED_AE);
  struct x25_sudirrip_struct sudirr;
  int extended = 0;
  sudirr.global_facil_mask = facil_mask;
  sudirr.extended = extended;
  strcpy(sudirr.device, "x25tap0");
  int res = ioctl(ret, SIOCX25SSUBSCRIP, &sudirr);
  if (res < 0) {
    perror("sudirr");
    close(ret);
    return -1;
  }
  struct x25_facilities fac;
  fac.winsize_in = 7;
  fac.winsize_out = 7;
  fac.pacsize_in = 10;
  fac.pacsize_out = 10;
  fac.throughput = 0xdd;
  fac.reverse = 0x80;
  res = ioctl(ret, SIOCX25SFACILITIES, &fac);
  if (res < 0) {
    perror("fac");
    close(ret);
    return -1;
  }
  unsigned char calling_exten[10];
  unsigned char called_exten[10];
  to_bcd(calling_exten, local);
  to_bcd(called_exten, remote);
  struct x25_dte_facilities dtefac;
  dtefac.calling_len = 20;
  dtefac.called_len = 20;
  memcpy(&dtefac.calling_ae, &calling_exten, 10);
  memcpy(&dtefac.called_ae, &called_exten, 10);
  res = ioctl(ret, SIOCX25SDTEFACILITIES, &dtefac);
  if (res < 0) {
    perror("dtefac");
    close(ret);
    return -1;
  }
  res = bind(ret, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
  if (res < 0) {
    perror("bind");
    close(ret);
    return -1;
  }
  long arg = fcntl(ret, F_GETFL, NULL);
  arg |= O_NONBLOCK;
  fcntl(ret, F_SETFL, arg);
  connect(ret, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  return ret;
}


x86 assembly (clang, -O0):
<OpenX25Socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x240(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x140(%rbp),%rdi
mov    $0x2d,%esi
call   1070 <index@plt>
mov    %rax,-0x248(%rbp)
cmp    $0x0,%rax
je     126e <OpenX25Socket+0x9e>
mov    -0x248(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x240(%rbp),%rdi
mov    $0x2d,%esi
call   1070 <index@plt>
mov    %rax,-0x248(%rbp)
cmp    $0x0,%rax
je     129a <OpenX25Socket+0xca>
mov    -0x248(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%rdi
mov    0x2cb5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12f9 <OpenX25Socket+0x129>
lea    0xd18(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c0 <OpenX25Socket+0x3f0>
movl   $0x1,-0x24c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
mov    0x2caa(%rip),%rax
mov    (%rax),%edx
lea    -0x24c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%rax
mov    0x2c5d(%rip),%rcx
or     (%rcx),%rax
mov    0x2c33(%rip),%rcx
or     (%rcx),%rax
mov    0x2c79(%rip),%rcx
or     (%rcx),%rax
mov    %rax,-0x258(%rbp)
movl   $0x0,-0x29c(%rbp)
mov    -0x258(%rbp),%rax
mov    %rax,-0x298(%rbp)
mov    -0x29c(%rbp),%eax
mov    %eax,-0x290(%rbp)
mov    -0x288(%rbp),%rdi
lea    0xc7c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
lea    -0x298(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2a0(%rbp)
cmpl   $0x0,-0x2a0(%rbp)
jge    13db <OpenX25Socket+0x20b>
lea    0xc4d(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c0 <OpenX25Socket+0x3f0>
movl   $0x7,-0x2c8(%rbp)
movl   $0x7,-0x2c4(%rbp)
movl   $0xa,-0x2c0(%rbp)
movl   $0xa,-0x2bc(%rbp)
movl   $0xdd,-0x2b8(%rbp)
movl   $0x80,-0x2b4(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2b6f(%rip),%rax
mov    (%rax),%esi
lea    -0x2e0(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2a0(%rbp)
cmpl   $0x0,-0x2a0(%rbp)
jge    1462 <OpenX25Socket+0x292>
lea    0xbd0(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c0 <OpenX25Socket+0x3f0>
lea    -0x2ea(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <to_bcd@plt>
lea    -0x2f4(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <to_bcd@plt>
movl   $0x14,-0x308(%rbp)
movl   $0x14,-0x304(%rbp)
lea    -0x338(%rbp),%rdi
add    $0x3c,%rdi
lea    -0x2ea(%rbp),%rsi
mov    $0xa,%edx
call   1090 <memcpy@plt>
lea    -0x338(%rbp),%rdi
add    $0x38,%rdi
lea    -0x2f4(%rbp),%rsi
mov    $0xa,%edx
call   1090 <memcpy@plt>
mov    -0x1c(%rbp),%edi
mov    0x2b00(%rip),%rax
mov    (%rax),%esi
lea    -0x338(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2a0(%rbp)
cmpl   $0x0,-0x2a0(%rbp)
jge    1519 <OpenX25Socket+0x349>
lea    0xb16(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c0 <OpenX25Socket+0x3f0>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <bind@plt>
mov    %eax,-0x2a0(%rbp)
cmpl   $0x0,-0x2a0(%rbp)
jge    155d <OpenX25Socket+0x38d>
lea    0xad9(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c0 <OpenX25Socket+0x3f0>
mov    -0x1c(%rbp),%edi
mov    0x2a39(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <fcntl@plt>
mov    %rax,-0x340(%rbp)
mov    0x2a50(%rip),%rax
mov    (%rax),%rax
or     -0x340(%rbp),%rax
mov    %rax,-0x340(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2a0d(%rip),%rax
mov    (%rax),%esi
mov    -0x340(%rbp),%rdx
call   1050 <fcntl@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <connect@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenX25Socket>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x308,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x18(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
lea    0x8(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2d7f(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x100(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1070 <index@plt>
test   %rax,%rax
je     124f <OpenX25Socket+0x7f>
movb   $0x0,(%rax)
lea    0x100(%rsp),%rdi
mov    $0x2d,%esi
call   1070 <index@plt>
test   %rax,%rax
je     1269 <OpenX25Socket+0x99>
movb   $0x0,(%rax)
mov    0x18(%rsp),%rdi
lea    0x200(%rsp),%rsi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%rdi
lea    0x100(%rsp),%rsi
call   1030 <strcpy@plt>
mov    (%r12),%rdi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     144a <OpenX25Socket+0x27a>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    0x2d12(%rip),%rax
mov    0x2cb3(%rip),%rcx
mov    (%rcx),%rcx
or     (%rax),%rcx
mov    0x2c86(%rip),%rax
or     (%rax),%rcx
mov    0x2ccc(%rip),%rax
or     (%rax),%rcx
mov    %rcx,0x80(%rsp)
movl   $0x0,0x88(%rsp)
mov    0x90(%rsp),%rdi
lea    0xcf6(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%esi
lea    0x80(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %eax,%eax
js     1458 <OpenX25Socket+0x288>
movaps 0xcb3(%rip),%xmm0
movups %xmm0,0xd8(%rsp)
movabs $0x80000000dd,%rax
mov    %rax,0xe8(%rsp)
mov    0x2c22(%rip),%rax
mov    (%rax),%esi
lea    0xc0(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %eax,%eax
js     1461 <OpenX25Socket+0x291>
lea    0x36(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   10b0 <to_bcd@plt>
lea    0x2c(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   10b0 <to_bcd@plt>
movabs $0x1400000014,%rax
mov    %rax,0x70(%rsp)
lea    0x7c(%rsp),%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1090 <memcpy@plt>
lea    0x78(%rsp),%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1090 <memcpy@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%esi
lea    0x40(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %eax,%eax
js     146a <OpenX25Socket+0x29a>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10a0 <bind@plt>
test   %eax,%eax
js     1473 <OpenX25Socket+0x2a3>
mov    0x2b91(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    0x2baf(%rip),%rcx
or     (%rcx),%rax
mov    0x2b7d(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fcntl@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10e0 <connect@plt>
jmp    148b <OpenX25Socket+0x2bb>
lea    0xbbf(%rip),%rdi
call   10c0 <perror@plt>
jmp    1486 <OpenX25Socket+0x2b6>
lea    0xbc0(%rip),%rdi
jmp    147a <OpenX25Socket+0x2aa>
lea    0xbc1(%rip),%rdi
jmp    147a <OpenX25Socket+0x2aa>
lea    0xbb5(%rip),%rdi
jmp    147a <OpenX25Socket+0x2aa>
lea    0xbb3(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x308,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_x25 = type { %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.x25_sudirrip_struct = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.x25_facilities = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.x25_dte_facilities = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_X25 = global i8* null
@SOCK_SEQPACKET = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@X25_MASK_PACKET_SIZE = global i64 0
@X25_MASK_WINDOW_SIZE = global i64 0
@X25_MASK_CALLING_AE = global i64 0
@X25_MASK_CALLED_AE = global i64 0
@.str.1 = [8 x i8] c"x25tap0\00"
@SIOCX25SSUBSCRIP = global i32 0
@.str.2 = [7 x i8] c"sudirr\00"
@SIOCX25SFACILITIES = global i32 0
@.str.3 = [4 x i8] c"fac\00"
@SIOCX25SDTEFACILITIES = global i32 0
@.str.4 = [7 x i8] c"dtefac\00"
@.str.5 = [5 x i8] c"bind\00"
@F_GETFL = global i32 0
@O_NONBLOCK = global i64 0
@F_SETFL = global i32 0
define i32 @OpenX25Socket(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_x25
%8 = alloca %struct.sockaddr_x25
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i64
%14 = alloca %struct.x25_sudirrip_struct
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.x25_facilities
%18 = alloca [10 x i8]
%19 = alloca [10 x i8]
%20 = alloca %struct.x25_dte_facilities
%21 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 -1, i32* %6
%22 = call i32 @bzero(%struct.sockaddr_x25* %7, i32 16)
%23 = call i32 @bzero(%struct.sockaddr_x25* %8, i32 16)
%24 = load i8*, i8** @AF_X25
%25 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %7, i32 0, i32 1
store i8* %24, i8** %25
%26 = load i8*, i8** @AF_X25
%27 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %8, i32 0, i32 1
store i8* %26, i8** %27
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%32 = load i8*, i8** %5
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%35 = call i8* @index(i8* %34, i8 signext 45)
store i8* %35, i8** %11
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %2
%38 = load i8*, i8** %11
store i8 0, i8* %38
br label %39
39: ; preds = %37, %2
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%41 = call i8* @index(i8* %40, i8 signext 45)
store i8* %41, i8** %11
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i8*, i8** %11
store i8 0, i8* %44
br label %45
45: ; preds = %43, %39
%46 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %7, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %8, i32 0, i32 0
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%55 = call i32 @strcpy(i8* %53, i8* %54)
%56 = load i8*, i8** @AF_X25
%57 = load i32, i32* @SOCK_SEQPACKET
%58 = call i32 @socket(i8* %56, i32 %57, i32 0)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %45
%62 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %158
63: ; preds = %45
store i32 1, i32* %12
%64 = load i32, i32* %6
%65 = load i32, i32* @SOL_SOCKET
%66 = load i32, i32* @SO_DEBUG
%67 = call i32 @setsockopt(i32 %64, i32 %65, i32 %66, i32* %12, i32 4)
%68 = load i64, i64* @X25_MASK_PACKET_SIZE
%69 = load i64, i64* @X25_MASK_WINDOW_SIZE
%70 = or i64 %68, %69
%71 = load i64, i64* @X25_MASK_CALLING_AE
%72 = or i64 %70, %71
%73 = load i64, i64* @X25_MASK_CALLED_AE
%74 = or i64 %72, %73
store i64 %74, i64* %13
store i32 0, i32* %15
%75 = load i64, i64* %13
%76 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %14, i32 0, i32 0
store i64 %75, i64* %76
%77 = load i32, i32* %15
%78 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %14, i32 0, i32 1
store i32 %77, i32* %78
%79 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %14, i32 0, i32 2
%80 = load i8*, i8** %79
%81 = call i32 @strcpy(i8* %80, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = load i32, i32* @SIOCX25SSUBSCRIP
%84 = call i32 @ioctl(i32 %82, i32 %83, %struct.x25_sudirrip_struct* %14)
store i32 %84, i32* %16
%85 = load i32, i32* %16
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %63
%88 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
store i32 -1, i32* %3
br label %158
91: ; preds = %63
%92 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 3
store i32 7, i32* %92
%93 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 4
store i32 7, i32* %93
%94 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 5
store i32 10, i32* %94
%95 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 6
store i32 10, i32* %95
%96 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 7
store i32 221, i32* %96
%97 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %17, i32 0, i32 8
store i32 128, i32* %97
%98 = load i32, i32* %6
%99 = load i32, i32* @SIOCX25SFACILITIES
%100 = bitcast %struct.x25_facilities* %17 to %struct.x25_sudirrip_struct*
%101 = call i32 @ioctl(i32 %98, i32 %99, %struct.x25_sudirrip_struct* %100)
store i32 %101, i32* %16
%102 = load i32, i32* %16
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %91
%105 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%106 = load i32, i32* %6
%107 = call i32 @close(i32 %106)
store i32 -1, i32* %3
br label %158
108: ; preds = %91
%109 = getelementptr inbounds [10 x i8], [10 x i8]* %18, i64 0, i64 0
%110 = load i8*, i8** %4
%111 = call i32 @to_bcd(i8* %109, i8* %110)
%112 = getelementptr inbounds [10 x i8], [10 x i8]* %19, i64 0, i64 0
%113 = load i8*, i8** %5
%114 = call i32 @to_bcd(i8* %112, i8* %113)
%115 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %20, i32 0, i32 9
store i32 20, i32* %115
%116 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %20, i32 0, i32 10
store i32 20, i32* %116
%117 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %20, i32 0, i32 12
%118 = bitcast [10 x i8]* %18 to i8**
%119 = call i32 @memcpy(i32* %117, i8** %118, i32 10)
%120 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %20, i32 0, i32 11
%121 = bitcast [10 x i8]* %19 to i8**
%122 = call i32 @memcpy(i32* %120, i8** %121, i32 10)
%123 = load i32, i32* %6
%124 = load i32, i32* @SIOCX25SDTEFACILITIES
%125 = bitcast %struct.x25_dte_facilities* %20 to %struct.x25_sudirrip_struct*
%126 = call i32 @ioctl(i32 %123, i32 %124, %struct.x25_sudirrip_struct* %125)
store i32 %126, i32* %16
%127 = load i32, i32* %16
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %108
%130 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%131 = load i32, i32* %6
%132 = call i32 @close(i32 %131)
store i32 -1, i32* %3
br label %158
133: ; preds = %108
%134 = load i32, i32* %6
%135 = bitcast %struct.sockaddr_x25* %7 to %struct.sockaddr*
%136 = call i32 @bind(i32 %134, %struct.sockaddr* %135, i32 16)
store i32 %136, i32* %16
%137 = load i32, i32* %16
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %143
139: ; preds = %133
%140 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%141 = load i32, i32* %6
%142 = call i32 @close(i32 %141)
store i32 -1, i32* %3
br label %158
143: ; preds = %133
%144 = load i32, i32* %6
%145 = load i32, i32* @F_GETFL
%146 = call i64 @fcntl(i32 %144, i32 %145, i64 0)
store i64 %146, i64* %21
%147 = load i64, i64* @O_NONBLOCK
%148 = load i64, i64* %21
%149 = or i64 %148, %147
store i64 %149, i64* %21
%150 = load i32, i32* %6
%151 = load i32, i32* @F_SETFL
%152 = load i64, i64* %21
%153 = call i64 @fcntl(i32 %150, i32 %151, i64 %152)
%154 = load i32, i32* %6
%155 = bitcast %struct.sockaddr_x25* %8 to %struct.sockaddr*
%156 = call i32 @connect(i32 %154, %struct.sockaddr* %155, i32 16)
%157 = load i32, i32* %6
store i32 %157, i32* %3
br label %158
158: ; preds = %143, %139, %129, %104, %87, %61
%159 = load i32, i32* %3
ret i32 %159
}

LLVM IR (-O2):
%struct.sockaddr_x25 = type { %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.x25_sudirrip_struct = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.x25_facilities = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.x25_dte_facilities = type { i64, i32, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_X25 = global i8* null
@SOCK_SEQPACKET = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@X25_MASK_PACKET_SIZE = global i64 0
@X25_MASK_WINDOW_SIZE = global i64 0
@X25_MASK_CALLING_AE = global i64 0
@X25_MASK_CALLED_AE = global i64 0
@.str.1 = [8 x i8] c"x25tap0\00"
@SIOCX25SSUBSCRIP = global i32 0
@.str.2 = [7 x i8] c"sudirr\00"
@SIOCX25SFACILITIES = global i32 0
@.str.3 = [4 x i8] c"fac\00"
@SIOCX25SDTEFACILITIES = global i32 0
@.str.4 = [7 x i8] c"dtefac\00"
@.str.5 = [5 x i8] c"bind\00"
@F_GETFL = global i32 0
@O_NONBLOCK = global i64 0
@F_SETFL = global i32 0
define i32 @OpenX25Socket(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_x25
%4 = alloca %struct.sockaddr_x25
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca %struct.x25_sudirrip_struct
%9 = alloca %struct.x25_facilities
%10 = alloca [10 x i8]
%11 = alloca [10 x i8]
%12 = alloca %struct.x25_dte_facilities
%13 = bitcast %struct.sockaddr_x25* %3 to i8*
%14 = bitcast %struct.sockaddr_x25* %4 to i8*
%15 = call i32 @bzero(%struct.sockaddr_x25* %3, i32 16)
%16 = call i32 @bzero(%struct.sockaddr_x25* %4, i32 16)
%17 = load i8*, i8** @AF_X25
%18 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %3, i64 0, i32 1
store i8* %17, i8** %18
%19 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %4, i64 0, i32 1
store i8* %17, i8** %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcpy(i8* %20, i8* %0)
%23 = call i32 @strcpy(i8* %21, i8* %1)
%24 = call i8* @index(i8* %20, i8 signext 45)
%25 = icmp eq i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %2
store i8 0, i8* %24
br label %27
27: ; preds = %26, %2
%28 = call i8* @index(i8* %21, i8 signext 45)
%29 = icmp eq i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %27
store i8 0, i8* %28
br label %31
31: ; preds = %30, %27
%32 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %3, i64 0, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %33, i8* %20)
%35 = getelementptr inbounds %struct.sockaddr_x25, %struct.sockaddr_x25* %4, i64 0, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @strcpy(i8* %36, i8* %21)
%38 = load i8*, i8** @AF_X25
%39 = load i32, i32* @SOCK_SEQPACKET
%40 = call i32 @socket(i8* %38, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %31
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %124
44: ; preds = %31
%45 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_DEBUG
%48 = call i32 @setsockopt(i32 %40, i32 %46, i32 %47, i32* %7, i32 4)
%49 = load i64, i64* @X25_MASK_PACKET_SIZE
%50 = load i64, i64* @X25_MASK_WINDOW_SIZE
%51 = or i64 %50, %49
%52 = load i64, i64* @X25_MASK_CALLING_AE
%53 = or i64 %51, %52
%54 = load i64, i64* @X25_MASK_CALLED_AE
%55 = or i64 %53, %54
%56 = bitcast %struct.x25_sudirrip_struct* %8 to i8*
%57 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %8, i64 0, i32 0
store i64 %55, i64* %57
%58 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %8, i64 0, i32 1
store i32 0, i32* %58
%59 = getelementptr inbounds %struct.x25_sudirrip_struct, %struct.x25_sudirrip_struct* %8, i64 0, i32 2
%60 = load i8*, i8** %59
%61 = call i32 @strcpy(i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32, i32* @SIOCX25SSUBSCRIP
%63 = call i32 @ioctl(i32 %40, i32 %62, %struct.x25_sudirrip_struct* %8)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %44
%66 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%67 = call i32 @close(i32 %40)
br label %122
68: ; preds = %44
%69 = bitcast %struct.x25_facilities* %9 to i8*
%70 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %9, i64 0, i32 3
%71 = bitcast i32* %70 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 10, i32 10>, <4 x i32>* %71
%72 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %9, i64 0, i32 7
store i32 221, i32* %72
%73 = getelementptr inbounds %struct.x25_facilities, %struct.x25_facilities* %9, i64 0, i32 8
store i32 128, i32* %73
%74 = load i32, i32* @SIOCX25SFACILITIES
%75 = bitcast %struct.x25_facilities* %9 to %struct.x25_sudirrip_struct*
%76 = call i32 @ioctl(i32 %40, i32 %74, %struct.x25_sudirrip_struct* %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %68
%79 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%80 = call i32 @close(i32 %40)
br label %120
81: ; preds = %68
%82 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%84 = call i32 @to_bcd(i8* %82, i8* %0)
%85 = call i32 @to_bcd(i8* %83, i8* %1)
%86 = bitcast %struct.x25_dte_facilities* %12 to i8*
%87 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %12, i64 0, i32 9
store i32 20, i32* %87
%88 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %12, i64 0, i32 10
store i32 20, i32* %88
%89 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %12, i64 0, i32 12
%90 = bitcast [10 x i8]* %10 to i8**
%91 = call i32 @memcpy(i32* %89, i8** %90, i32 10)
%92 = getelementptr inbounds %struct.x25_dte_facilities, %struct.x25_dte_facilities* %12, i64 0, i32 11
%93 = bitcast [10 x i8]* %11 to i8**
%94 = call i32 @memcpy(i32* %92, i8** %93, i32 10)
%95 = load i32, i32* @SIOCX25SDTEFACILITIES
%96 = bitcast %struct.x25_dte_facilities* %12 to %struct.x25_sudirrip_struct*
%97 = call i32 @ioctl(i32 %40, i32 %95, %struct.x25_sudirrip_struct* %96)
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %81
%100 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%101 = call i32 @close(i32 %40)
br label %118
102: ; preds = %81
%103 = bitcast %struct.sockaddr_x25* %3 to %struct.sockaddr*
%104 = call i32 @bind(i32 %40, %struct.sockaddr* %103, i32 16)
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %109
106: ; preds = %102
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%108 = call i32 @close(i32 %40)
br label %118
109: ; preds = %102
%110 = load i32, i32* @F_GETFL
%111 = call i64 @fcntl(i32 %40, i32 %110, i64 0)
%112 = load i64, i64* @O_NONBLOCK
%113 = or i64 %112, %111
%114 = load i32, i32* @F_SETFL
%115 = call i64 @fcntl(i32 %40, i32 %114, i64 %113)
%116 = bitcast %struct.sockaddr_x25* %4 to %struct.sockaddr*
%117 = call i32 @connect(i32 %40, %struct.sockaddr* %116, i32 16)
br label %118
118: ; preds = %109, %106, %99
%119 = phi i32 [ -1, %99 ], [ -1, %106 ], [ %40, %109 ]
br label %120
120: ; preds = %118, %78
%121 = phi i32 [ -1, %78 ], [ %119, %118 ]
br label %122
122: ; preds = %120, %65
%123 = phi i32 [ -1, %65 ], [ %121, %120 ]
br label %124
124: ; preds = %122, %42
%125 = phi i32 [ -1, %42 ], [ %123, %122 ]
ret i32 %125
}