#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*/ where;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ launch_callmgr(struct in_addr, int, char **, char **);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int open_callmgr(struct in_addr inetaddr, int argc, char **argv, char **envp) {
  struct sockaddr_un where;
  const int NUM_TRIES = 3;
  int i, fd;
  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    ({
      fprintf(stderr, "Could not create unix domain socket: %s",
              strerror(errno));
      fprintf(stderr, "\n");
    });
    return (-1);
  }
  fcntl(fd, F_SETFD, FD_CLOEXEC);
  where.sun_family = AF_UNIX;
  snprintf(where.sun_path, sizeof(where.sun_path),
           "/var/run/pptp/"
           "%s",
           inet_ntoa(inetaddr));
  for (i = 0; i < NUM_TRIES; i++) {
    if (connect(fd, (struct sockaddr *)&where, sizeof(where)) < 0) {
      launch_callmgr(inetaddr, argc, argv, envp);
      sleep(3);
    } else
      return fd;
  }
  close(fd);
  ({
    fprintf(stderr, "Could not launch call manager after %d tries.", i);
    fprintf(stderr, "\n");
  });
  return -1;
}


x86 assembly (clang, -O0):
<open_callmgr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x3,-0x2c(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1236 <open_callmgr+0x96>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    %eax,-0x38(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <open_callmgr+0x190>
mov    -0x34(%rbp),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rcx
mov    $0x4,%esi
lea    0xdae(%rip),%rdx
call   1060 <snprintf@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    12ed <open_callmgr+0x14d>
mov    -0x34(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    12cf <open_callmgr+0x12f>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%edi
call   1030 <launch_callmgr@plt>
mov    $0x3,%edi
call   10b0 <sleep@plt>
jmp    12da <open_callmgr+0x13a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1330 <open_callmgr+0x190>
jmp    12df <open_callmgr+0x13f>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1288 <open_callmgr+0xe8>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    %eax,-0x3c(%rbp)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_callmgr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%r13d
mov    0x2e2a(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12d7 <open_callmgr+0x137>
mov    %eax,%ebx
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    %r13d,%edi
call   1050 <inet_ntoa@plt>
lea    0xe20(%rip),%rdx
mov    $0x4,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
jns    1318 <open_callmgr+0x178>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <launch_callmgr@plt>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
jns    1318 <open_callmgr+0x178>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <launch_callmgr@plt>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %rax,%rax
jns    1318 <open_callmgr+0x178>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <launch_callmgr@plt>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2d1a(%rip),%rbx
mov    (%rbx),%edi
lea    0xd74(%rip),%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
jmp    1305 <open_callmgr+0x165>
mov    0x2cfa(%rip),%rbp
mov    0x0(%rbp),%ebx
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd0a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd1c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Could not create unix domain socket: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.2 = [17 x i8] c"/var/run/pptp/%s\00"
@.str.3 = [46 x i8] c"Could not launch call manager after %d tries.\00"
define i32 @open_callmgr(i32 %0, i32 %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca %struct.in_addr
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca %struct.sockaddr_un
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
store i32 %0, i32* %16
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
store i32 3, i32* %11
%17 = load i32, i32* @AF_UNIX
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %13
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %27, i32* %14
%28 = load i32, i32* %14
store i32 -1, i32* %5
br label %73
29: ; preds = %4
%30 = load i32, i32* %13
%31 = load i32, i32* @F_SETFD
%32 = load i32, i32* @FD_CLOEXEC
%33 = call i32 @fcntl(i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* @AF_UNIX
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 1
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %10, i32 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i8* @inet_ntoa(i32 %39)
%41 = call i32 @snprintf(i32 %37, i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i32 0, i32* %12
br label %42
42: ; preds = %61, %29
%43 = load i32, i32* %12
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = load i32, i32* %13
%47 = bitcast %struct.sockaddr_un* %10 to %struct.sockaddr*
%48 = call i64 @connect(i32 %46, %struct.sockaddr* %47, i32 8)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %45
%51 = load i32, i32* %7
%52 = load i8**, i8*** %8
%53 = load i8**, i8*** %9
%54 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @launch_callmgr(i32 %55, i32 %51, i8** %52, i8** %53)
%57 = call i32 @sleep(i32 3)
br label %60
58: ; preds = %45
%59 = load i32, i32* %13
store i32 %59, i32* %5
br label %73
60: ; preds = %50
br label %61
61: ; preds = %60
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
br label %42
64: ; preds = %42
%65 = load i32, i32* %13
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* @stderr
%68 = load i32, i32* %12
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %68)
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %71, i32* %15
%72 = load i32, i32* %15
store i32 -1, i32* %5
br label %73
73: ; preds = %64, %58, %21
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Could not create unix domain socket: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.2 = [17 x i8] c"/var/run/pptp/%s\00"
@.str.3 = [46 x i8] c"Could not launch call manager after %d tries.\00"
define i32 @open_callmgr(i32 %0, i32 %1, i8** %2, i8** %3) {
%5 = alloca %struct.sockaddr_un
%6 = bitcast %struct.sockaddr_un* %5 to i8*
%7 = load i32, i32* @AF_UNIX
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
18: ; preds = %4
%19 = load i32, i32* @F_SETFD
%20 = load i32, i32* @FD_CLOEXEC
%21 = tail call i32 @fcntl(i32 %9, i32 %19, i32 %20)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %22, i32* %23
%24 = tail call i8* @inet_ntoa(i32 %0)
%25 = tail call i32 @snprintf(i32 undef, i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%27 = call i64 @connect(i32 %9, %struct.sockaddr* %26, i32 8)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %18
%30 = call i32 @launch_callmgr(i32 %0, i32 %1, i8** %2, i8** %3)
%31 = call i32 @sleep(i32 3)
%32 = call i64 @connect(i32 %9, %struct.sockaddr* %26, i32 8)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = call i32 @launch_callmgr(i32 %0, i32 %1, i8** %2, i8** %3)
%36 = call i32 @sleep(i32 3)
%37 = call i64 @connect(i32 %9, %struct.sockaddr* %26, i32 8)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = call i32 @launch_callmgr(i32 %0, i32 %1, i8** %2, i8** %3)
%41 = call i32 @sleep(i32 3)
%42 = call i32 @close(i32 %9)
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 3)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %18, %29, %34, %39, %11
%48 = phi i32 [ -1, %11 ], [ -1, %39 ], [ %9, %34 ], [ %9, %29 ], [ %9, %18 ]
ret i32 %48
}