#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 _createGenericNetlinkSocket();
int _queryKernelFamilyId(int, char *);
int /*<<< orphan*/ _recvAndParseDataFromTacoKernel(int);
int /*<<< orphan*/ _sendDataToTacoKernel(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int socketFd = _createGenericNetlinkSocket();
  if (socketFd < 0) {
    printf("[USER-ERROR] create generic netlink failed\n");
    return -1;
  }
  int familyId = _queryKernelFamilyId(socketFd, "TACO_KERNEL");
  if (familyId < 0) {
    printf("[USER-ERROR] query kernel family id failed\n");
    return -1;
  }
  _sendDataToTacoKernel(socketFd, familyId);
  _recvAndParseDataFromTacoKernel(socketFd);
  close(socketFd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <_createGenericNetlinkSocket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a2 <main+0x42>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <main+0x98>
mov    -0x14(%rbp),%edi
lea    0xe80(%rip),%rsi
call   1030 <_queryKernelFamilyId@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d6 <main+0x76>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <main+0x98>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1080 <_sendDataToTacoKernel@plt>
mov    -0x14(%rbp),%edi
call   1060 <_recvAndParseDataFromTacoKernel@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <_createGenericNetlinkSocket@plt>
test   %eax,%eax
js     119b <main+0x3b>
mov    %eax,%ebx
lea    0xe8b(%rip),%rsi
mov    %eax,%edi
call   1030 <_queryKernelFamilyId@plt>
test   %eax,%eax
js     11a4 <main+0x44>
mov    %ebx,%edi
mov    %eax,%esi
call   1080 <_sendDataToTacoKernel@plt>
mov    %ebx,%edi
call   1060 <_recvAndParseDataFromTacoKernel@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe95(%rip),%rdi
jmp    11ab <main+0x4b>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"[USER-ERROR] create generic netlink failed\0A\00"
@.str.1 = [12 x i8] c"TACO_KERNEL\00"
@.str.2 = [44 x i8] c"[USER-ERROR] query kernel family id failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @_createGenericNetlinkSocket()
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 @_queryKernelFamilyId(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
20: ; preds = %13
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @_sendDataToTacoKernel(i32 %21, i32 %22)
%24 = load i32, i32* %6
%25 = call i32 @_recvAndParseDataFromTacoKernel(i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %20, %18, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"TACO_KERNEL\00"
@str = [43 x i8] c"[USER-ERROR] query kernel family id failed\00"
@str.3 = [43 x i8] c"[USER-ERROR] create generic netlink failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @_createGenericNetlinkSocket()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0))
br label %16
7: ; preds = %2
%8 = tail call i32 @_queryKernelFamilyId(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %16
12: ; preds = %7
%13 = tail call i32 @_sendDataToTacoKernel(i32 %3, i32 %8)
%14 = tail call i32 @_recvAndParseDataFromTacoKernel(i32 %3)
%15 = tail call i32 @close(i32 %3)
br label %16
16: ; preds = %10, %12, %5
%17 = phi i32 [ -1, %5 ], [ -1, %10 ], [ 0, %12 ]
ret i32 %17
}