#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 */

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_uevent_string(char **, unsigned long *);
int send(int, char *, unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int dispatch_event(int netlink_socket, char **environ) {
  char *uevent_string;
  unsigned long uevent_string_len;
  uevent_string = get_uevent_string(environ, &uevent_string_len);
  if (uevent_string == NULL) {
    fprintf(stderr,
            "[%s]: "
            "Unable to create uevent string."
            "\n",
            "dispatch_event");
    ;
    return 1;
  }
  if (send(netlink_socket, uevent_string, uevent_string_len, 0) == -1) {
    fprintf(stderr,
            "[%s]: "
            "send failed: %s."
            "\n",
            "dispatch_event", strerror(errno));
    ;
    free(uevent_string);
    return 1;
  }
  free(uevent_string);
  return 0;
}


x86 assembly (clang, -O0):
<dispatch_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <get_uevent_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <dispatch_event+0x55>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
lea    0xe95(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <dispatch_event+0xca>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    120a <dispatch_event+0xba>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rcx
lea    0xe4f(%rip),%rsi
lea    0xe39(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <dispatch_event+0xca>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dispatch_event>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %edi,%r14d
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1070 <get_uevent_string@plt>
test   %rax,%rax
je     1196 <dispatch_event+0x46>
mov    %rax,%rbx
mov    0x8(%rsp),%rdx
xor    %ebp,%ebp
mov    %r14d,%edi
mov    %rax,%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11b6 <dispatch_event+0x66>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11f4 <dispatch_event+0xa4>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
lea    0xe7a(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11ef <dispatch_event+0x9f>
mov    0x2e23(%rip),%rax
mov    (%rax),%ebp
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe62(%rip),%rsi
lea    0xe4c(%rip),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"[%s]: Unable to create uevent string.\0A\00"
@.str.1 = [15 x i8] c"dispatch_event\00"
@.str.2 = [24 x i8] c"[%s]: send failed: %s.\0A\00"
@errno = global i32 0
define i32 @dispatch_event(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = call i8* @get_uevent_string(i8** %8, i64* %7)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %31
15: ; preds = %2
%16 = load i32, i32* %4
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i32 @send(i32 %16, i8* %17, i64 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
store i32 1, i32* %3
br label %31
28: ; preds = %15
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %28, %21, %12
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"[%s]: Unable to create uevent string.\0A\00"
@.str.1 = [15 x i8] c"dispatch_event\00"
@.str.2 = [24 x i8] c"[%s]: send failed: %s.\0A\00"
@errno = global i32 0
define i32 @dispatch_event(i32 %0, i8** %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i8* @get_uevent_string(i8** %1, i64* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
10: ; preds = %2
%11 = load i64, i64* %3
%12 = call i32 @send(i32 %0, i8* %5, i64 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @free(i8* %5)
br label %22
20: ; preds = %10
%21 = call i32 @free(i8* %5)
br label %22
22: ; preds = %20, %14, %7
%23 = phi i32 [ 1, %7 ], [ 1, %14 ], [ 0, %20 ]
ret i32 %23
}