#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  void *name;
  void *pgn;
  void *addr;
};
struct TYPE_4__ {
  TYPE_1__ j1939;
};
struct sockaddr_can {
  TYPE_2__ can_addr;
  int /*<<< orphan*/ can_ifindex;
};

/* Variables and functions */
int /*<<< orphan*/ if_nametoindex(char *);
scalar_t__ strlen(char *);
char *strsep(char **, char *);
void *strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void parse_canaddr(char *spec, struct sockaddr_can *paddr) {
  char *str;
  str = strsep(&spec, ":");
  if (strlen(str))
    paddr->can_ifindex = if_nametoindex(str);
  str = strsep(&spec, ",");
  if (str && strlen(str))
    paddr->can_addr.j1939.addr = strtoul(str, NULL, 0);
  str = strsep(&spec, ",");
  if (str && strlen(str))
    paddr->can_addr.j1939.pgn = strtoul(str, NULL, 0);
  str = strsep(&spec, ",");
  if (str && strlen(str))
    paddr->can_addr.j1939.name = strtoul(str, NULL, 0);
}


x86 assembly (clang, -O0):
<parse_canaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1189 <parse_canaddr+0x49>
mov    -0x18(%rbp),%rdi
call   1040 <if_nametoindex@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
lea    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d5 <parse_canaddr+0x95>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     11d5 <parse_canaddr+0x95>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
lea    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1221 <parse_canaddr+0xe1>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1221 <parse_canaddr+0xe1>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
lea    -0x8(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     126c <parse_canaddr+0x12c>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     126c <parse_canaddr+0x12c>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_canaddr>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
lea    0xebc(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strsep@plt>
cmpb   $0x0,(%rax)
je     115e <parse_canaddr+0x2e>
mov    %rax,%rdi
call   1030 <if_nametoindex@plt>
mov    %eax,0x18(%rbx)
lea    0xe9d(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strsep@plt>
test   %rax,%rax
je     1189 <parse_canaddr+0x59>
cmpb   $0x0,(%rax)
je     1189 <parse_canaddr+0x59>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,0x10(%rbx)
lea    0xe72(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strsep@plt>
test   %rax,%rax
je     11b4 <parse_canaddr+0x84>
cmpb   $0x0,(%rax)
je     11b4 <parse_canaddr+0x84>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,0x8(%rbx)
lea    0xe47(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strsep@plt>
test   %rax,%rax
je     11de <parse_canaddr+0xae>
cmpb   $0x0,(%rax)
je     11de <parse_canaddr+0xae>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_can = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i8*, i8*, i8* }
@.str = [2 x i8] c":\00"
@.str.1 = [2 x i8] c",\00"
define void @parse_canaddr(i8* %0, %struct.sockaddr_can* %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr_can*
%5 = alloca i8*
store i8* %0, i8** %3
store %struct.sockaddr_can* %1, %struct.sockaddr_can** %4
%6 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32 @if_nametoindex(i8* %11)
%13 = load %struct.sockaddr_can*, %struct.sockaddr_can** %4
%14 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %13, i32 0, i32 1
store i32 %12, i32* %14
br label %15
15: ; preds = %10, %2
%16 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i64 @strlen(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = call i8* @strtoul(i8* %24, i32* null, i32 0)
%26 = load %struct.sockaddr_can*, %struct.sockaddr_can** %4
%27 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %26, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 2
store i8* %25, i8** %29
br label %30
30: ; preds = %23, %19, %15
%31 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i64 @strlen(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = call i8* @strtoul(i8* %39, i32* null, i32 0)
%41 = load %struct.sockaddr_can*, %struct.sockaddr_can** %4
%42 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %41, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i32 0, i32 1
store i8* %40, i8** %44
br label %45
45: ; preds = %38, %34, %30
%46 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %46, i8** %5
%47 = load i8*, i8** %5
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load i8*, i8** %5
%51 = call i64 @strlen(i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i8*, i8** %5
%55 = call i8* @strtoul(i8* %54, i32* null, i32 0)
%56 = load %struct.sockaddr_can*, %struct.sockaddr_can** %4
%57 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %56, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 0
store i8* %55, i8** %59
br label %60
60: ; preds = %53, %49, %45
ret void
}

LLVM IR (-O2):
%struct.sockaddr_can = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i8*, i8*, i8* }
@.str = [2 x i8] c":\00"
@.str.1 = [2 x i8] c",\00"
define void @parse_canaddr(i8* %0, %struct.sockaddr_can* nocapture writeonly %1) {
%3 = alloca i8*
store i8* %0, i8** %3
%4 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @if_nametoindex(i8* %4)
%9 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %1, i64 0, i32 1
store i32 %8, i32* %9
br label %10
10: ; preds = %7, %2
%11 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i8* @strtoul(i8* nocapture %11, i32* null, i32 0)
%18 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %1, i64 0, i32 0, i32 0, i32 2
store i8* %17, i8** %18
br label %19
19: ; preds = %16, %13, %10
%20 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i8, i8* %20
%24 = icmp eq i8 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i8* @strtoul(i8* nocapture %20, i32* null, i32 0)
%27 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %1, i64 0, i32 0, i32 0, i32 1
store i8* %26, i8** %27
br label %28
28: ; preds = %25, %22, %19
%29 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = load i8, i8* %29
%33 = icmp eq i8 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = call i8* @strtoul(i8* nocapture %29, i32* null, i32 0)
%36 = getelementptr inbounds %struct.sockaddr_can, %struct.sockaddr_can* %1, i64 0, i32 0, i32 0, i32 0
store i8* %35, i8** %36
br label %37
37: ; preds = %34, %31, %28
ret void
}