#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 */
typedef int /*<<< orphan*/ unix_address;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ sendto(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *,
                  int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
size_t strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_un unix_address = {0};
  size_t size = 0;
  int unix_socket = (-1);
  int exit_code = EXIT_FAILURE;
  if (2 != argc) {
    (void)write(STDOUT_FILENO, "Usage: modprobe MODULE\n",
                sizeof("Usage: modprobe MODULE\n"));
    goto end;
  }
  size = strlen(argv[1]);
  if (0 == size) {
    goto end;
  }
  unix_socket = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (-1 == unix_socket) {
    goto end;
  }
  unix_address.sun_family = AF_UNIX;
  (void)strcpy(unix_address.sun_path, "/run/modprobed.socket");
  size *= sizeof(char);
  if ((ssize_t)size != sendto(unix_socket, argv[1], size, 0,
                              (struct sockaddr *)&unix_address,
                              sizeof(unix_address))) {
    goto close_unix;
  }
  exit_code = EXIT_SUCCESS;
close_unix:
  (void)close(unix_socket);
end:
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
movq   $0x0,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11de <main+0x6e>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
jmp    12a7 <main+0x137>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1200 <main+0x90>
jmp    12a7 <main+0x137>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    122f <main+0xbf>
jmp    12a7 <main+0x137>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xdd3(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     1293 <main+0x123>
jmp    129f <main+0x12f>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%r14d
cmp    $0x2,%edi
jne    1213 <main+0xb3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     122d <main+0xcd>
mov    %rax,%rbp
mov    0x2e32(%rip),%r12
mov    (%r12),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     122d <main+0xcd>
mov    %eax,%r15d
mov    (%r12),%eax
mov    %eax,0x4(%rsp)
lea    0xe3f(%rip),%rsi
xor    %edi,%edi
call   1030 <strcpy@plt>
mov    0x8(%rbx),%rsi
mov    %rsp,%r8
mov    %r15d,%edi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    %rax,%rbp
jne    1209 <main+0xa9>
mov    0x2dba(%rip),%rax
mov    (%rax),%r14d
mov    %r15d,%edi
call   1070 <close@plt>
jmp    122d <main+0xcd>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [24 x i8] c"Usage: modprobe MODULE\0A\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"/run/modprobed.socket\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast %struct.sockaddr_un* %6 to i8*
store i64 0, i64* %7
store i32 -1, i32* %8
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %9
%12 = load i32, i32* %4
%13 = icmp ne i32 2, %12
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 24)
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = icmp eq i64 0, %22
br i1 %23, label %24, label %25
24: ; preds = %17
br label %55
25: ; preds = %17
%26 = load i32, i32* @AF_UNIX
%27 = load i32, i32* @SOCK_DGRAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp eq i32 -1, %29
br i1 %30, label %31, label %32
31: ; preds = %25
br label %55
32: ; preds = %25
%33 = load i32, i32* @AF_UNIX
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @strcpy(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%38 = load i64, i64* %7
%39 = mul i64 %38, 1
store i64 %39, i64* %7
%40 = load i64, i64* %7
%41 = load i32, i32* %8
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i64, i64* %7
%46 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%47 = call i64 @sendto(i32 %41, i8* %44, i64 %45, i32 0, %struct.sockaddr* %46, i32 12)
%48 = icmp ne i64 %40, %47
br i1 %48, label %49, label %50
49: ; preds = %32
br label %52
50: ; preds = %32
%51 = load i32, i32* @EXIT_SUCCESS
store i32 %51, i32* %9
br label %52
52: ; preds = %50, %49
%53 = load i32, i32* %8
%54 = call i32 @close(i32 %53)
br label %55
55: ; preds = %52, %31, %24, %14
%56 = load i32, i32* %9
ret i32 %56
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [24 x i8] c"Usage: modprobe MODULE\0A\00"
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"/run/modprobed.socket\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = bitcast %struct.sockaddr_un* %3 to i8*
%5 = load i32, i32* @EXIT_FAILURE
%6 = icmp eq i32 %0, 2
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @STDOUT_FILENO
%9 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 24)
br label %31
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %31, label %15
15: ; preds = %10
%16 = load i32, i32* @AF_UNIX
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %31, label %20
20: ; preds = %15
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = tail call i32 @strcpy(i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %11
%25 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%26 = call i64 @sendto(i32 %18, i8* %24, i64 %13, i32 0, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i64 %13, %26
%28 = load i32, i32* @EXIT_SUCCESS
%29 = select i1 %27, i32 %28, i32 %5
%30 = call i32 @close(i32 %18)
br label %31
31: ; preds = %15, %10, %20, %7
%32 = phi i32 [ %5, %7 ], [ %5, %10 ], [ %5, %15 ], [ %29, %20 ]
ret i32 %32
}