#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 */
struct can_filter {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ socketcan_apply_filters(int, struct can_filter *, int);
int /*<<< orphan*/ socketcan_make_slave_filters(struct can_filter *, int);
int socketcan_open(char const *);
int socketcan_open_slave(const char *iface, int nodeid) {
  struct can_filter filters[9];
  int fd = socketcan_open(iface);
  if (fd < 0)
    return -1;
  socketcan_make_slave_filters(filters, nodeid);
  if (socketcan_apply_filters(fd, filters, 9) < 0) {
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<socketcan_open_slave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <socketcan_open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1171 <socketcan_open_slave+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <socketcan_open_slave+0x72>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <socketcan_make_slave_filters@plt>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x9,%edx
call   1030 <socketcan_apply_filters@plt>
cmp    $0x0,%rax
jge    11ac <socketcan_open_slave+0x6c>
mov    -0x44(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <socketcan_open_slave+0x72>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketcan_open_slave>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
call   1050 <socketcan_open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     118a <socketcan_open_slave+0x4a>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14d,%esi
call   1060 <socketcan_make_slave_filters@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x9,%edx
call   1030 <socketcan_apply_filters@plt>
test   %rax,%rax
js     1183 <socketcan_open_slave+0x43>
mov    %ebp,%ebx
jmp    118a <socketcan_open_slave+0x4a>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.can_filter = type { i32 }
define i32 @socketcan_open_slave(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [9 x %struct.can_filter]
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @socketcan_open(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %26
13: ; preds = %2
%14 = getelementptr inbounds [9 x %struct.can_filter], [9 x %struct.can_filter]* %6, i64 0, i64 0
%15 = load i32, i32* %5
%16 = call i32 @socketcan_make_slave_filters(%struct.can_filter* %14, i32 %15)
%17 = load i32, i32* %7
%18 = getelementptr inbounds [9 x %struct.can_filter], [9 x %struct.can_filter]* %6, i64 0, i64 0
%19 = call i64 @socketcan_apply_filters(i32 %17, %struct.can_filter* %18, i32 9)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* %7
%23 = call i32 @close(i32 %22)
store i32 -1, i32* %3
br label %26
24: ; preds = %13
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %21, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.can_filter = type { i32 }
define i32 @socketcan_open_slave(i8* %0, i32 %1) {
%3 = alloca [9 x %struct.can_filter]
%4 = bitcast [9 x %struct.can_filter]* %3 to i8*
%5 = tail call i32 @socketcan_open(i8* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = getelementptr inbounds [9 x %struct.can_filter], [9 x %struct.can_filter]* %3, i64 0, i64 0
%9 = call i32 @socketcan_make_slave_filters(%struct.can_filter* %8, i32 %1)
%10 = call i64 @socketcan_apply_filters(i32 %5, %struct.can_filter* %8, i32 9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @close(i32 %5)
br label %14
14: ; preds = %7, %2, %12
%15 = phi i32 [ -1, %12 ], [ -1, %2 ], [ %5, %7 ]
ret i32 %15
}