#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;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
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 argc, char *argv[]) {
  struct sockaddr_un addr;
  char *msg;
  char sockname[] = "/tmp/logfilesock";
  int sock;
  socklen_t addrlen;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <msg>\n", argv[0]);
    exit(1);
  }
  msg = argv[1];
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_LOCAL;
  strcpy(addr.sun_path, sockname);
  addrlen = strlen(sockname) + sizeof(addr.sun_family);
  sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
  if (sock == -1) {
    perror("socket() failed");
    exit(1);
  };
  if (sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&addr, addrlen) ==
      -1) {
    perror("sendto() failed");
    exit(1);
  };
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe53(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe50(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe4e(%rip),%al
mov    %al,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f5 <main+0x65>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1276 <main+0xe6>
lea    0xdbb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    -0x18(%rbp),%r8
mov    -0x50(%rbp),%r9
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12c5 <main+0x135>
lea    0xd7c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x44(%rbp),%edi
call   1070 <close@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 0xe61(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
cmp    $0x2,%edi
jne    1245 <main+0xb5>
mov    0x8(%rsi),%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e1a(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1267 <main+0xd7>
mov    %eax,%ebp
add    $0x4,%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   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     1270 <main+0xe0>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdb9(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdb4(%rip),%rdi
jmp    1277 <main+0xe7>
lea    0xdbb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <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 = [17 x i8] c"Usage: %s <msg>\0A\00"
@AF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [16 x i8] c"sendto() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i8*
%8 = alloca [17 x i8]
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [17 x i8]* %8 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 8)
%26 = load i32, i32* @AF_LOCAL
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%31 = call i32 @strcpy(i32 %29, i8* %30)
%32 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
%34 = add i64 %33, 4
store i64 %34, i64* %10
%35 = load i32, i32* @AF_LOCAL
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %21
%41 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %21
%44 = load i32, i32* %9
%45 = load i8*, i8** %7
%46 = load i8*, i8** %7
%47 = call i64 @strlen(i8* %46)
%48 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%49 = load i64, i64* %10
%50 = call i32 @sendto(i32 %44, i8* %45, i64 %47, i32 0, %struct.sockaddr* %48, i64 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %43
%56 = load i32, i32* %9
%57 = call i32 @close(i32 %56)
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 = [17 x i8] c"Usage: %s <msg>\0A\00"
@AF_LOCAL = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [16 x i8] c"sendto() failed\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 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 8)
%17 = load i32, i32* @AF_LOCAL
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcpy(i32 %20, i8* %6)
%22 = call i64 @strlen(i8* %6)
%23 = load i32, i32* @AF_LOCAL
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %13
%28 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %13
%31 = add i64 %22, 4
%32 = call i64 @strlen(i8* dereferenceable(1) %15)
%33 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %25, i8* %15, i64 %32, i32 0, %struct.sockaddr* %33, i64 %31)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = call i32 @close(i32 %25)
ret i32 0
}