#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 sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
int strlen(char const *);
int fill_sock_name(struct sockaddr_un *name, const char *filename) {
  if (strlen(filename) >= sizeof(name->sun_path))
    return -1;
  name->sun_family = AF_LOCAL;
  strcpy(name->sun_path, filename);
  return 0;
}


x86 assembly (clang, -O0):
<fill_sock_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x4,%rax
jb     1151 <fill_sock_name+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1177 <fill_sock_name+0x57>
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_sock_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x3,%ecx
ja     1158 <fill_sock_name+0x38>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%r14)
mov    (%r14),%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
@AF_LOCAL = global i32 0
define i32 @fill_sock_name(%struct.sockaddr_un* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un*
%5 = alloca i8*
store %struct.sockaddr_un* %0, %struct.sockaddr_un** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = icmp uge i64 %8, 4
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %20
11: ; preds = %2
%12 = load i32, i32* @AF_LOCAL
%13 = load %struct.sockaddr_un*, %struct.sockaddr_un** %4
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %13, i32 0, i32 1
store i32 %12, i32* %14
%15 = load %struct.sockaddr_un*, %struct.sockaddr_un** %4
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i8*, i8** %5
%19 = call i32 @strcpy(i32 %17, i8* %18)
store i32 0, i32* %3
br label %20
20: ; preds = %11, %10
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@AF_LOCAL = global i32 0
define i32 @fill_sock_name(%struct.sockaddr_un* nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp ugt i32 %3, 3
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @AF_LOCAL
%7 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %0, i64 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @strcpy(i32 %9, i8* %1)
br label %11
11: ; preds = %2, %5
%12 = phi i32 [ 0, %5 ], [ -1, %2 ]
ret i32 %12
}