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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char *, char const *);
int hyper_netlink_expect_dev(int fd, const char *dev) {
  int len;
  char buf[1024] = {0};
  do {
    len = recv(fd, buf, sizeof(buf), 0);
    if (len < 0)
      break;
    buf[len] = '\0';
    if (dev && strncmp(buf, "add@", strlen("add@")) == 0) {
      fprintf(stdout, "netlink add, expect %s, got %s\n", dev, buf);
      if (strstr(buf, dev) != NULL)
        return 1;
    }
  } while (len > 0);
  return 0;
}


x86 assembly (clang, -O0):
<hyper_netlink_expect_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ad <hyper_netlink_expect_dev+0x4d>
jmp    1257 <hyper_netlink_expect_dev+0xf7>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
cmpq   $0x0,-0x10(%rbp)
je     1248 <hyper_netlink_expect_dev+0xe8>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    0xe27(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x428(%rbp),%rdi
mov    %eax,%edx
lea    0xe12(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1248 <hyper_netlink_expect_dev+0xe8>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x420(%rbp),%rcx
lea    0xded(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1243 <hyper_netlink_expect_dev+0xe3>
movl   $0x1,-0x4(%rbp)
jmp    125e <hyper_netlink_expect_dev+0xfe>
jmp    1248 <hyper_netlink_expect_dev+0xe8>
jmp    124d <hyper_netlink_expect_dev+0xed>
cmpl   $0x0,-0x14(%rbp)
jg     1185 <hyper_netlink_expect_dev+0x25>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hyper_netlink_expect_dev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsp,%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe70(%rip),%r12
lea    0xe6e(%rip),%r13
jmp    11a5 <hyper_netlink_expect_dev+0x45>
nopl   0x0(%rax)
test   %r14d,%r14d
je     1211 <hyper_netlink_expect_dev+0xb1>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1211 <hyper_netlink_expect_dev+0xb1>
mov    %eax,%r14d
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
test   %rbx,%rbx
je     11a0 <hyper_netlink_expect_dev+0x40>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11a0 <hyper_netlink_expect_dev+0x40>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11a0 <hyper_netlink_expect_dev+0x40>
mov    $0x1,%eax
jmp    1213 <hyper_netlink_expect_dev+0xb3>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"add@\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"netlink add, expect %s, got %s\0A\00"
define i32 @hyper_netlink_expect_dev(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = bitcast [1024 x i8]* %7 to i8*
br label %9
9: ; preds = %39, %2
%10 = load i32, i32* %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1024, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %42
16: ; preds = %9
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %38
22: ; preds = %16
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i32, i32* @stdout
%29 = load i8*, i8** %5
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = call i32* @strstr(i8* %32, i8* %33)
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %27
store i32 1, i32* %3
br label %43
37: ; preds = %27
br label %38
38: ; preds = %37, %22, %16
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = icmp sgt i32 %40, 0
br i1 %41, label %9, label %42
42: ; preds = %39, %15
store i32 0, i32* %3
br label %43
43: ; preds = %42, %36
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [5 x i8] c"add@\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"netlink add, expect %s, got %s\0A\00"
define i32 @hyper_netlink_expect_dev(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br label %6
6: ; preds = %21, %2
%7 = call i32 @recv(i32 %0, i8* %4, i32 1024, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
br i1 %5, label %21, label %12
12: ; preds = %9
%13 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @stdout
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %4)
%19 = call i32* @strstr(i8* %4, i8* %1)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %9, %12, %16
%22 = icmp eq i32 %7, 0
br i1 %22, label %23, label %6
23: ; preds = %21, %6, %16
%24 = phi i32 [ 1, %16 ], [ 0, %6 ], [ 0, %21 ]
ret i32 %24
}