#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;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, scalar_t__, int /*<<< orphan*/, struct sockaddr *,
           scalar_t__);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
scalar_t__ strlen(char *);
int main(int ac, char *av[]) {
  int sock;
  struct sockaddr_un addr;
  socklen_t addrlen;
  char sockname[] = "/tmp/logfilesock";
  char *msg = av[1];
  if (ac != 2) {
    fprintf(stderr, "useage: logfilec 'message'\n");
    exit(1);
  }
  sock = socket(PF_UNIX, SOCK_DGRAM, 0);
  if (sock == -1) {
    perror("socket");
    exit(2);
  };
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, sockname);
  addrlen = strlen(sockname) + sizeof(addr.sun_family);
  if (sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&addr, addrlen) ==
      -1) {
    perror("sendto");
    exit(3);
  };
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe75(%rip),%al
mov    %al,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11d3 <main+0x63>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120f <main+0x9f>
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
lea    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
xor    %ecx,%ecx
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1287 <main+0x117>
lea    0xdbc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
cmp    $0x2,%edi
jne    1207 <main+0x97>
mov    0x8(%rsi),%r14
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     1226 <main+0xb6>
mov    %eax,%ebp
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x4(%rax),%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
mov    %rbx,%r9
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
je     123c <main+0xcc>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xdf1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x3,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.sockname = [17 x i8] c"/tmp/logfilesock\00"
@stderr = global i32 0
@.str = [28 x i8] c"useage: logfilec 'message'\0A\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@AF_UNIX = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca i64
%8 = alloca [17 x i8]
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = bitcast [17 x i8]* %8 to i8*
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %9
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @PF_UNIX
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %20
%30 = load i32, i32* @AF_UNIX
%31 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%35 = call i32 @strcpy(i32 %33, i8* %34)
%36 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
%38 = add i64 %37, 4
store i64 %38, i64* %7
%39 = load i32, i32* %5
%40 = load i8*, i8** %9
%41 = load i8*, i8** %9
%42 = call i64 @strlen(i8* %41)
%43 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%44 = load i64, i64* %7
%45 = call i32 @sendto(i32 %39, i8* %40, i64 %42, i32 0, %struct.sockaddr* %43, i64 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %29
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 3)
unreachable
50: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.sockname = [17 x i8] c"/tmp/logfilesock\00"
@stderr = global i32 0
@.str = [28 x i8] c"useage: logfilec 'message'\0A\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@AF_UNIX = global i32 0
@.str.2 = [7 x i8] c"sendto\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [17 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @PF_UNIX
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %14
%23 = load i32, i32* @AF_UNIX
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = call i32 @strcpy(i32 undef, i8* %6)
%26 = call i64 @strlen(i8* %6)
%27 = add i64 %26, 4
%28 = call i64 @strlen(i8* dereferenceable(1) %8)
%29 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%30 = call i32 @sendto(i32 %17, i8* %8, i64 %28, i32 0, %struct.sockaddr* %29, i64 %27)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 3)
unreachable
35: ; preds = %22
ret i32 0
}