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

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getpid();
int getsid(int /*<<< orphan*/);
int sendto(int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
void send_message(int time, int loglimit, int ntb, char *logname, char *ttype) {
  int pid = getsid(getpid());
  char *cmsg[2] = {(char *)logname, (char *)ttype};
  int imsg[4] = {time, ntb, pid, loglimit};
  struct sockaddr_un addr;
  int sock;
  char fname[15];
  int i;
  sprintf(fname, "/var/lock/"
                 "ttcd");
  sock = socket(AF_UNIX, SOCK_DGRAM, 0);
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, fname);
  for (i = 0; i < 2; i++) {
    if (sendto(sock, cmsg[i], 12, 0, (struct sockaddr *)&addr, sizeof(addr)) ==
        -1) {
      fprintf(stderr, "sendto: %s\n", strerror(errno));
      exit(1);
    }
  }
  for (i = 0; i < 4; i++) {
    if (sendto(sock, &imsg[i], 6, 0, (struct sockaddr *)&addr, sizeof(addr)) ==
        -1) {
      fprintf(stderr, "sendto: %s\n", strerror(errno));
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x6b(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1080 <sprintf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x5c(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%edi
lea    -0x6b(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x70(%rbp)
cmpl   $0x2,-0x70(%rbp)
jge    12b0 <send_message+0x120>
mov    -0x5c(%rbp),%edi
movslq -0x70(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    -0x58(%rbp),%r8
mov    $0xc,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
mov    $0x0,%al
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    129d <send_message+0x10d>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xd81(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12a2 <send_message+0x112>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1230 <send_message+0xa0>
movl   $0x0,-0x70(%rbp)
cmpl   $0x4,-0x70(%rbp)
jge    133d <send_message+0x1ad>
mov    -0x5c(%rbp),%edi
movslq -0x70(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x58(%rbp),%r8
mov    $0x6,%edx
xor    %ecx,%ecx
mov    $0x8,%r9d
mov    $0x0,%al
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    132a <send_message+0x19a>
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xcf4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    132f <send_message+0x19f>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    12b7 <send_message+0x127>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %ebp,0x10(%rsp)
mov    %ebx,0x14(%rsp)
mov    %eax,0x18(%rsp)
mov    %r12d,0x1c(%rsp)
movabs $0x646374742f6b63,%rax
mov    %rax,0x27(%rsp)
movabs $0x636f6c2f7261762f,%rax
6c 6f 63
mov    %rax,0x20(%rsp)
mov    0x2e0b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    0x20(%rsp),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
lea    0x1c(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    $0x8,%r9d
mov    %ebx,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     12f2 <send_message+0x172>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd7(%rip),%rax
mov    (%rax),%ebx
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xcff(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"/var/lock/ttcd\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"sendto: %s\0A\00"
@errno = global i32 0
define void @send_message(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [2 x i8*]
%13 = alloca [4 x i32]
%14 = alloca %struct.sockaddr_un
%15 = alloca i32
%16 = alloca [15 x i8]
%17 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%18 = call i32 (...) @getpid()
%19 = call i32 @getsid(i32 %18)
store i32 %19, i32* %11
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%21 = load i8*, i8** %9
store i8* %21, i8** %20
%22 = getelementptr inbounds i8*, i8** %20, i64 1
%23 = load i8*, i8** %10
store i8* %23, i8** %22
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %13, i64 0, i64 0
%25 = load i32, i32* %6
store i32 %25, i32* %24
%26 = getelementptr inbounds i32, i32* %24, i64 1
%27 = load i32, i32* %8
store i32 %27, i32* %26
%28 = getelementptr inbounds i32, i32* %26, i64 1
%29 = load i32, i32* %11
store i32 %29, i32* %28
%30 = getelementptr inbounds i32, i32* %28, i64 1
%31 = load i32, i32* %7
store i32 %31, i32* %30
%32 = getelementptr inbounds [15 x i8], [15 x i8]* %16, i64 0, i64 0
%33 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @AF_UNIX
%35 = load i32, i32* @SOCK_DGRAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %15
%37 = load i32, i32* @AF_UNIX
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %14, i32 0, i32 1
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %14, i32 0, i32 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds [15 x i8], [15 x i8]* %16, i64 0, i64 0
%42 = call i32 @strcpy(i32 %40, i8* %41)
store i32 0, i32* %17
br label %43
43: ; preds = %62, %5
%44 = load i32, i32* %17
%45 = icmp slt i32 %44, 2
br i1 %45, label %46, label %65
46: ; preds = %43
%47 = load i32, i32* %15
%48 = load i32, i32* %17
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 %49
%51 = load i8*, i8** %50
%52 = bitcast %struct.sockaddr_un* %14 to %struct.sockaddr*
%53 = call i32 (i32, ...) @sendto(i32 %47, i8* %51, i32 12, i32 0, %struct.sockaddr* %52, i64 8)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %46
br label %62
62: ; preds = %61
%63 = load i32, i32* %17
%64 = add nsw i32 %63, 1
store i32 %64, i32* %17
br label %43
65: ; preds = %43
store i32 0, i32* %17
br label %66
66: ; preds = %84, %65
%67 = load i32, i32* %17
%68 = icmp slt i32 %67, 4
br i1 %68, label %69, label %87
69: ; preds = %66
%70 = load i32, i32* %15
%71 = load i32, i32* %17
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [4 x i32], [4 x i32]* %13, i64 0, i64 %72
%74 = bitcast %struct.sockaddr_un* %14 to %struct.sockaddr*
%75 = call i32 (i32, ...) @sendto(i32 %70, i32* %73, i32 6, i32 0, %struct.sockaddr* %74, i64 8)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %83
77: ; preds = %69
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %69
br label %84
84: ; preds = %83
%85 = load i32, i32* %17
%86 = add nsw i32 %85, 1
store i32 %86, i32* %17
br label %66
87: ; preds = %66
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@.str = [15 x i8] c"/var/lock/ttcd\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"sendto: %s\0A\00"
@errno = global i32 0
define void @send_message(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca [4 x i32]
%7 = alloca %struct.sockaddr_un
%8 = alloca [15 x i8]
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 @getsid(i32 %9)
%11 = bitcast [4 x i32]* %6 to i8*
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
store i32 %0, i32* %12
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
store i32 %2, i32* %13
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
store i32 %10, i32* %14
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
store i32 %1, i32* %15
%16 = bitcast %struct.sockaddr_un* %7 to i8*
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* @AF_UNIX
%19 = load i32, i32* @SOCK_DGRAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i64 0, i32 1
store i32 %21, i32* %22
%23 = call i32 @strcpy(i32 undef, i8* %17)
%24 = call i32 (i32, ...) @sendto(i32 %20, i8* %3, i32 12, i32 0, %struct.sockaddr_un* %7, i64 8)
%25 = icmp eq i32 %24, -1
br i1 %25, label %32, label %26
26: ; preds = %5
%27 = call i32 (i32, ...) @sendto(i32 %20, i8* %4, i32 12, i32 0, %struct.sockaddr_un* %7, i64 8)
%28 = icmp eq i32 %27, -1
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i32 (i32, ...) @sendto(i32 %20, i32* %12, i32 6, i32 0, %struct.sockaddr_un* %7, i64 8)
%31 = icmp eq i32 %30, -1
br i1 %31, label %48, label %38
32: ; preds = %26, %5
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = call i32 (i32, ...) @sendto(i32 %20, i32* %13, i32 6, i32 0, %struct.sockaddr_un* %7, i64 8)
%40 = icmp eq i32 %39, -1
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = call i32 (i32, ...) @sendto(i32 %20, i32* %14, i32 6, i32 0, %struct.sockaddr_un* %7, i64 8)
%43 = icmp eq i32 %42, -1
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = call i32 (i32, ...) @sendto(i32 %20, i32* %15, i32 6, i32 0, %struct.sockaddr_un* %7, i64 8)
%46 = icmp eq i32 %45, -1
br i1 %46, label %48, label %47
47: ; preds = %44
ret void
48: ; preds = %44, %41, %38, %29
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
}