#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 {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void send_command(char *cmd, char *recvBuf, int *recvSize) {
  int s, len;
  struct sockaddr_un saun;
  char buf[512];
  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    printf("Couldn't get a socket\n");
    return;
  }
  saun.sun_family = AF_UNIX;
  strcpy(saun.sun_path, "/dev/remoted");
  len = sizeof(saun.sun_family) + strlen(saun.sun_path);
  if (connect(s, (struct sockaddr *)&saun, len) < 0) {
    printf("Couldn't connect to lircd daemon\n");
    return;
  }
  if (send(s, cmd, strlen(cmd), 0) < 0) {
    printf("Error sending %s\n", cmd);
    return;
  }
  printf("Sent %s\n", cmd);
  close(s);
}


x86 assembly (clang, -O0):
<send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11bf <send_command+0x4f>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1287 <send_command+0x117>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jge    1219 <send_command+0xa9>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1287 <send_command+0x117>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x23c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    126d <send_command+0xfd>
mov    -0x8(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1287 <send_command+0x117>
mov    -0x8(%rbp),%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e56(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1208 <send_command+0x88>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
call   1050 <strlen@plt>
lea    0x4(%rax),%edx
mov    %rsp,%rsi
mov    %ebp,%edi
call   1090 <connect@plt>
test   %rax,%rax
js     121c <send_command+0x9c>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
js     122a <send_command+0xaa>
lea    0xe2a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    123b <send_command+0xbb>
lea    0xe3a(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <puts@plt>
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
jmp    123b <send_command+0xbb>
lea    0xddc(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"Couldn't get a socket\0A\00"
@.str.1 = [13 x i8] c"/dev/remoted\00"
@.str.2 = [34 x i8] c"Couldn't connect to lircd daemon\0A\00"
@.str.3 = [18 x i8] c"Error sending %s\0A\00"
@.str.4 = [9 x i8] c"Sent %s\0A\00"
define void @send_command(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_un
%10 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %51
17: ; preds = %3
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %9, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = add i64 4, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = bitcast %struct.sockaddr_un* %9 to %struct.sockaddr*
%31 = load i32, i32* %8
%32 = call i64 @connect(i32 %29, %struct.sockaddr* %30, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %17
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %51
36: ; preds = %17
%37 = load i32, i32* %7
%38 = load i8*, i8** %4
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = call i64 @send(i32 %37, i8* %38, i32 %40, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load i8*, i8** %4
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %51
46: ; preds = %36
%47 = load i8*, i8** %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %7
%50 = call i32 @close(i32 %49)
br label %51
51: ; preds = %46, %43, %34, %15
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"/dev/remoted\00"
@.str.3 = [18 x i8] c"Error sending %s\0A\00"
@.str.4 = [9 x i8] c"Sent %s\0A\00"
@str = [33 x i8] c"Couldn't connect to lircd daemon\00"
@str.5 = [22 x i8] c"Couldn't get a socket\00"
define void @send_command(i8* %0, i8* nocapture readnone %1, i32* nocapture readnone %2) {
%4 = alloca %struct.sockaddr_un
%5 = bitcast %struct.sockaddr_un* %4 to i8*
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
br label %32
12: ; preds = %3
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @strcpy(i8* undef, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @strlen(i8* undef)
%17 = add i32 %16, 4
%18 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%19 = call i64 @connect(i32 %8, %struct.sockaddr* %18, i32 %17)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %32
23: ; preds = %12
%24 = call i32 @strlen(i8* %0)
%25 = call i64 @send(i32 %8, i8* %0, i32 %24, i32 0)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %32
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%31 = call i32 @close(i32 %8)
br label %32
32: ; preds = %29, %27, %21, %10
ret void
}