#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_frame {
  int /*<<< orphan*/ can_id;
};

/* Variables and functions */
int /*<<< orphan*/ CAN_EFF_FLAG;
int strlen(char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
void get_can_id(struct can_frame *cf, char *idstring, int base) {
  if (idstring[strlen(idstring) - 1] == 'x') {
    cf->can_id = CAN_EFF_FLAG;
    idstring[strlen(idstring) - 1] = 0;
  } else
    cf->can_id = 0;
  cf->can_id |= strtoul(idstring, NULL, base);
}


x86 assembly (clang, -O0):
<get_can_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x78,%eax
jne    1192 <get_can_id+0x72>
mov    0x2e7c(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    119c <get_can_id+0x7c>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtoul@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_can_id>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x78,-0x1(%rax,%rbp,1)
jne    115a <get_can_id+0x3a>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
jmp    1160 <get_can_id+0x40>
movl   $0x0,(%rbx)
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <strtoul@plt>
or     %eax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.can_frame = type { i32 }
@CAN_EFF_FLAG = global i32 0
define void @get_can_id(%struct.can_frame* %0, i8* %1, i32 %2) {
%4 = alloca %struct.can_frame*
%5 = alloca i8*
%6 = alloca i32
store %struct.can_frame* %0, %struct.can_frame** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 120
br i1 %15, label %16, label %26
16: ; preds = %3
%17 = load i32, i32* @CAN_EFF_FLAG
%18 = load %struct.can_frame*, %struct.can_frame** %4
%19 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
store i8 0, i8* %25
br label %29
26: ; preds = %3
%27 = load %struct.can_frame*, %struct.can_frame** %4
%28 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %27, i32 0, i32 0
store i32 0, i32* %28
br label %29
29: ; preds = %26, %16
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = call i32 @strtoul(i8* %30, i32* null, i32 %31)
%33 = load %struct.can_frame*, %struct.can_frame** %4
%34 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = or i32 %35, %32
store i32 %36, i32* %34
ret void
}

LLVM IR (-O2):
%struct.can_frame = type { i32 }
@CAN_EFF_FLAG = global i32 0
define void @get_can_id(%struct.can_frame* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 120
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load i32, i32* @CAN_EFF_FLAG
%12 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %0, i64 0, i32 0
store i32 %11, i32* %12
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
br label %19
17: ; preds = %3
%18 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %0, i64 0, i32 0
store i32 0, i32* %18
br label %19
19: ; preds = %17, %10
%20 = tail call i32 @strtoul(i8* nocapture %1, i32* null, i32 %2)
%21 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %0, i64 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %21
ret void
}