#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 */

/* Variables and functions */
int /*<<< orphan*/ _sock_srvname(char *, char *);
int /*<<< orphan*/ _syserrno();
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int _sock_srv(char *path, int fd) {
  int sfd;
  char msg[8 + 256 + 1];
  _sock_srvname(msg, path);
  unlink(msg);
  sfd = creat(msg, 0666);
  if (sfd < 0) {
    close(fd);
    _syserrno();
    return -1;
  }
  snprintf(msg, sizeof msg, "%d", fd);
  if (write(sfd, msg, strlen(msg)) < 0) {
    _syserrno();
    close(sfd);
    close(fd);
    return -1;
  }
  close(sfd);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<_sock_srv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <_sock_srvname@plt>
lea    -0x130(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x130(%rbp),%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11e7 <_sock_srv+0x67>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x0,%al
call   1080 <_syserrno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127d <_sock_srv+0xfd>
lea    -0x130(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x109,%esi
lea    0xe03(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1266 <_sock_srv+0xe6>
mov    $0x0,%al
call   1080 <_syserrno@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127d <_sock_srv+0xfd>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sock_srv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%r14d
mov    %rdi,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1090 <_sock_srvname@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    %rbp,%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
test   %eax,%eax
js     11fd <_sock_srv+0x7d>
mov    %eax,%ebp
lea    0xe42(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x109,%esi
mov    %r14d,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
js     120e <_sock_srv+0x8e>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    1229 <_sock_srv+0xa9>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
call   1080 <_syserrno@plt>
jmp    1224 <_sock_srv+0xa4>
xor    %eax,%eax
call   1080 <_syserrno@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @_sock_srv(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [265 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @_sock_srvname(i8* %8, i8* %9)
%11 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%12 = call i32 @unlink(i8* %11)
%13 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%14 = call i32 @creat(i8* %13, i32 438)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* %5
%19 = call i32 @close(i32 %18)
%20 = call i32 (...) @_syserrno()
store i32 -1, i32* %3
br label %42
21: ; preds = %2
%22 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %5
%24 = call i32 @snprintf(i8* %22, i32 265, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [265 x i8], [265 x i8]* %7, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i64 @write(i32 %25, i8* %26, i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %21
%32 = call i32 (...) @_syserrno()
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %5
%36 = call i32 @close(i32 %35)
store i32 -1, i32* %3
br label %42
37: ; preds = %21
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %5
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %37, %31, %17
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @_sock_srv(i8* %0, i32 %1) {
%3 = alloca [265 x i8]
%4 = getelementptr inbounds [265 x i8], [265 x i8]* %3, i64 0, i64 0
%5 = call i32 @_sock_srvname(i8* %4, i8* %0)
%6 = call i32 @unlink(i8* %4)
%7 = call i32 @creat(i8* %4, i32 438)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @close(i32 %1)
%11 = call i32 (...) @_syserrno()
br label %24
12: ; preds = %2
%13 = call i32 @snprintf(i8* %4, i32 265, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%14 = call i32 @strlen(i8* %4)
%15 = call i64 @write(i32 %7, i8* %4, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 (...) @_syserrno()
%19 = call i32 @close(i32 %7)
%20 = call i32 @close(i32 %1)
br label %24
21: ; preds = %12
%22 = call i32 @close(i32 %7)
%23 = call i32 @close(i32 %1)
br label %24
24: ; preds = %21, %17, %9
%25 = phi i32 [ -1, %9 ], [ -1, %17 ], [ 0, %21 ]
ret i32 %25
}