#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*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_uevent_string(char **, char *, unsigned long *);
int init_netlink_socket(int);
int send(int, char *, unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[], char **environ) {
  char *uevent_string;
  unsigned long uevent_string_len;
  int netlink_socket;
  if (argv[1] == NULL) {
    fprintf(stderr,
            "[%s]: "
            "Malformed event arguments (bus missing)."
            "\n",
            "parsing arguments");
    ;
    return 1;
  }
  uevent_string = get_uevent_string(environ, argv[1], &uevent_string_len);
  if (uevent_string == NULL) {
    fprintf(stderr,
            "[%s]: "
            "Malformed event environmental variables."
            "\n",
            "parsing env vars");
    ;
    return 1;
  }
  netlink_socket = init_netlink_socket(1);
  if (netlink_socket == -1) {
    fprintf(stderr,
            "[%s]: "
            "Unable to open netlink socket."
            "\n",
            "netlink init");
    ;
    goto exit;
  }
  if (send(netlink_socket, uevent_string, uevent_string_len, 0) == -1) {
    fprintf(stderr,
            "[%s]: "
            "send failed: %s."
            "\n",
            "sending data", strerror(errno));
    ;
  }
  close(netlink_socket);
exit:
  free(uevent_string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11c3 <main+0x53>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
lea    0xe80(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x143>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <get_uevent_string@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1211 <main+0xa1>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
lea    0xe74(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x143>
mov    $0x1,%edi
call   1070 <init_netlink_socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    124b <main+0xdb>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
lea    0xe6a(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12a3 <main+0x133>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    129b <main+0x12b>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rcx
lea    0xe29(%rip),%rsi
lea    0xe3a(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rsi
test   %rsi,%rsi
je     1208 <main+0x98>
lea    0x8(%rsp),%rax
mov    %rdx,%rdi
mov    %rax,%rdx
call   1090 <get_uevent_string@plt>
test   %rax,%rax
je     1221 <main+0xb1>
mov    %rax,%rbx
mov    $0x1,%edi
call   1070 <init_netlink_socket@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xd6>
mov    %eax,%ebp
mov    0x8(%rsp),%rdx
mov    %eax,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11ff <main+0x8f>
mov    0x2e0d(%rip),%rax
mov    (%rax),%r14d
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xecb(%rip),%rsi
lea    0xedc(%rip),%rdx
mov    %r14d,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1264 <main+0xf4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
lea    0xe11(%rip),%rdx
jmp    1238 <main+0xc8>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
lea    0xe3a(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    126e <main+0xfe>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
lea    0xe4c(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"[%s]: Malformed event arguments (bus missing).\0A\00"
@.str.1 = [18 x i8] c"parsing arguments\00"
@.str.2 = [48 x i8] c"[%s]: Malformed event environmental variables.\0A\00"
@.str.3 = [17 x i8] c"parsing env vars\00"
@.str.4 = [38 x i8] c"[%s]: Unable to open netlink socket.\0A\00"
@.str.5 = [13 x i8] c"netlink init\00"
@.str.6 = [24 x i8] c"[%s]: send failed: %s.\0A\00"
@.str.7 = [13 x i8] c"sending data\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = load i8**, i8*** %6
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %53
18: ; preds = %3
%19 = load i8**, i8*** %7
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i8* @get_uevent_string(i8** %19, i8* %22, i64* %9)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %53
29: ; preds = %18
%30 = call i32 @init_netlink_socket(i32 1)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %50
36: ; preds = %29
%37 = load i32, i32* %10
%38 = load i8*, i8** %8
%39 = load i64, i64* %9
%40 = call i32 @send(i32 %37, i8* %38, i64 %39, i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %42, %36
%48 = load i32, i32* %10
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %47, %33
%51 = load i8*, i8** %8
%52 = call i32 @free(i8* %51)
store i32 0, i32* %4
br label %53
53: ; preds = %50, %26, %15
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"[%s]: Malformed event arguments (bus missing).\0A\00"
@.str.1 = [18 x i8] c"parsing arguments\00"
@.str.2 = [48 x i8] c"[%s]: Malformed event environmental variables.\0A\00"
@.str.3 = [17 x i8] c"parsing env vars\00"
@.str.4 = [38 x i8] c"[%s]: Unable to open netlink socket.\0A\00"
@.str.5 = [13 x i8] c"netlink init\00"
@.str.6 = [24 x i8] c"[%s]: send failed: %s.\0A\00"
@.str.7 = [13 x i8] c"sending data\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1, i8** %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %37
12: ; preds = %3
%13 = call i8* @get_uevent_string(i8** %2, i8* %7, i64* %4)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %37
18: ; preds = %12
%19 = call i32 @init_netlink_socket(i32 1)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %35
24: ; preds = %18
%25 = load i64, i64* %4
%26 = call i32 @send(i32 %19, i8* %13, i64 %25, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %24
%34 = call i32 @close(i32 %19)
br label %35
35: ; preds = %33, %21
%36 = call i32 @free(i8* %13)
br label %37
37: ; preds = %35, %15, %9
%38 = phi i32 [ 1, %9 ], [ 1, %15 ], [ 0, %35 ]
ret i32 %38
}