#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 sockaddr_can {
  int /*<<< orphan*/ can_ifindex;
  int /*<<< orphan*/ can_family;
};
struct sockaddr {
  int dummy;
};
struct ifreq {
  int /*<<< orphan*/ ifr_ifindex;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_CAN;
int /*<<< orphan*/ CAN_RAW;
int /*<<< orphan*/ PF_CAN;
int /*<<< orphan*/ SIOCGIFINDEX;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int openCAN(char *name) {
  int skt = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  struct ifreq ifr;
  strcpy(ifr.ifr_name, name);
  ioctl(skt, SIOCGIFINDEX, &ifr);
  struct sockaddr_can addr;
  addr.can_family = AF_CAN;
  addr.can_ifindex = ifr.ifr_ifindex;
  bind(skt, (struct sockaddr *)&addr, sizeof(addr));
  return skt;
}


x86 assembly (clang, -O0):
<openCAN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <bind@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openCAN>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1050 <bind@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_can = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@SIOCGIFINDEX = global i32 0
@AF_CAN = global i32 0
define i32 @openCAN(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.ifreq
%5 = alloca %struct.sockaddr_can
store i8* %0, i8** %2
%6 = load i32, i32* @PF_CAN
%7 = load i32, i32* @SOCK_RAW
%8 = load i32, i32* @CAN_RAW
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %3
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i32 %11, i8* %12)
%14 = load i32, i32* %3
%15 = load i32, i32* @SIOCGIFINDEX
%16 = call i32 @ioctl(i32 %14, i32 %15, %struct.ifreq* %4)
%17 = load i32, i32* @AF_CAN
%18 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %5, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %5, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* %3
%23 = bitcast %struct.sockaddr_can* %5 to %struct.sockaddr*
%24 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 8)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
%struct.sockaddr_can = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_CAN = global i32 0
@SOCK_RAW = global i32 0
@CAN_RAW = global i32 0
@SIOCGIFINDEX = global i32 0
@AF_CAN = global i32 0
define i32 @openCAN(i8* %0) {
%2 = alloca %struct.ifreq
%3 = alloca %struct.sockaddr_can
%4 = load i32, i32* @PF_CAN
%5 = load i32, i32* @SOCK_RAW
%6 = load i32, i32* @CAN_RAW
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = bitcast %struct.ifreq* %2 to i8*
%9 = tail call i32 @strcpy(i32 undef, i8* %0)
%10 = load i32, i32* @SIOCGIFINDEX
%11 = call i32 @ioctl(i32 %7, i32 %10, %struct.ifreq* %2)
%12 = bitcast %struct.sockaddr_can* %3 to i8*
%13 = load i32, i32* @AF_CAN
%14 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %3, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_can* %3 to %struct.sockaddr*
%19 = call i32 @bind(i32 %7, %struct.sockaddr* %18, i32 8)
ret i32 %7
}