#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 can_dlc;
  int can_id;
  int *data;
};

/* Variables and functions */
int CAN_EFF_FLAG;
int CAN_EFF_MASK;
int CAN_ERR_FLAG;
int CAN_ERR_MASK;
int CAN_RTR_FLAG;
int CAN_SFF_MASK;
int /*<<< orphan*/ sprintf(char *, char *, ...);
void sprint_canframe(char *buf, struct can_frame *cf, int sep) {
  int i, offset;
  int dlc = (cf->can_dlc > 8) ? 8 : cf->can_dlc;
  if (cf->can_id & CAN_ERR_FLAG) {
    sprintf(buf, "%08X#", cf->can_id & (CAN_ERR_MASK | CAN_ERR_FLAG));
    offset = 9;
  } else if (cf->can_id & CAN_EFF_FLAG) {
    sprintf(buf, "%08X#", cf->can_id & CAN_EFF_MASK);
    offset = 9;
  } else {
    sprintf(buf, "%03X#", cf->can_id & CAN_SFF_MASK);
    offset = 4;
  }
  if (cf->can_id & CAN_RTR_FLAG)
    sprintf(buf + offset, "R");
  else
    for (i = 0; i < dlc; i++) {
      sprintf(buf + offset, "%02X", cf->data[i]);
      offset += 2;
      if (sep && (i + 1 < dlc))
        sprintf(buf + offset++, ".");
    }
}


x86 assembly (clang, -O0):
<sprint_canframe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x8,(%rax)
jle    113d <sprint_canframe+0x2d>
mov    $0x8,%eax
mov    %eax,-0x24(%rbp)
jmp    1146 <sprint_canframe+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2e8e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     119e <sprint_canframe+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
and    %eax,%edx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x9,-0x1c(%rbp)
jmp    1213 <sprint_canframe+0x103>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2e1c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e5 <sprint_canframe+0xd5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2e17(%rip),%rax
and    (%rax),%edx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x9,-0x1c(%rbp)
jmp    120e <sprint_canframe+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2db9(%rip),%rax
and    (%rax),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x4,-0x1c(%rbp)
jmp    1213 <sprint_canframe+0x103>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d9f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     124a <sprint_canframe+0x13a>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12e1 <sprint_canframe+0x1d1>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12dc <sprint_canframe+0x1cc>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12c9 <sprint_canframe+0x1b9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x20(%rbp),%eax
jge    12c9 <sprint_canframe+0x1b9>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
add    %rax,%rdi
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    12ce <sprint_canframe+0x1be>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1251 <sprint_canframe+0x141>
jmp    12e1 <sprint_canframe+0x1d1>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_canframe>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
mov    (%rsi),%r12d
cmp    $0x8,%r12d
mov    $0x8,%r15d
cmovl  %r12d,%r15d
mov    0x4(%rsi),%eax
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
je     1154 <sprint_canframe+0x44>
mov    0x2e88(%rip),%rcx
or     (%rcx),%edx
jmp    116c <sprint_canframe+0x5c>
mov    0x2e6d(%rip),%rcx
test   %eax,(%rcx)
je     1224 <sprint_canframe+0x114>
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edx
mov    $0x9,%ebp
lea    0xe88(%rip),%rsi
and    %eax,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
test   %eax,0x4(%r13)
je     11aa <sprint_canframe+0x9a>
mov    %ebp,%eax
movw   $0x52,(%rbx,%rax,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r12d,%r12d
jle    119b <sprint_canframe+0x8b>
movslq %r15d,%rax
cmp    $0x2,%eax
mov    $0x1,%r15d
mov    %rax,0x10(%rsp)
cmovge %eax,%r15d
neg    %r15
mov    $0x1,%r14d
jmp    11e5 <sprint_canframe+0xd5>
nop
lea    (%r15,%r14,1),%rax
add    $0x1,%rax
add    $0x1,%r14
mov    %r12d,%ebp
cmp    $0x1,%rax
je     119b <sprint_canframe+0x8b>
movslq %ebp,%r12
lea    (%rbx,%r12,1),%rdi
mov    0x8(%r13),%rax
mov    -0x4(%rax,%r14,4),%edx
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%r12
cmpl   $0x0,0xc(%rsp)
je     11d0 <sprint_canframe+0xc0>
cmp    0x10(%rsp),%r14
jge    11d0 <sprint_canframe+0xc0>
add    $0x3,%ebp
movw   $0x2e,(%rbx,%r12,1)
mov    %ebp,%r12d
jmp    11d0 <sprint_canframe+0xc0>
mov    0x2d85(%rip),%rcx
mov    (%rcx),%edx
mov    $0x4,%ebp
lea    0xdcd(%rip),%rsi
jmp    1178 <sprint_canframe+0x68>

LLVM IR (-O0):
%struct.can_frame = type { i32, i32, i32* }
@CAN_ERR_FLAG = global i32 0
@.str = [6 x i8] c"%08X#\00"
@CAN_ERR_MASK = global i32 0
@CAN_EFF_FLAG = global i32 0
@CAN_EFF_MASK = global i32 0
@.str.1 = [6 x i8] c"%03X#\00"
@CAN_SFF_MASK = global i32 0
@CAN_RTR_FLAG = global i32 0
@.str.2 = [2 x i8] c"R\00"
@.str.3 = [5 x i8] c"%02X\00"
@.str.4 = [2 x i8] c".\00"
define void @sprint_canframe(i8* %0, %struct.can_frame* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca %struct.can_frame*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store %struct.can_frame* %1, %struct.can_frame** %5
store i32 %2, i32* %6
%10 = load %struct.can_frame*, %struct.can_frame** %5
%11 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 8
br i1 %13, label %14, label %15
14: ; preds = %3
br label %19
15: ; preds = %3
%16 = load %struct.can_frame*, %struct.can_frame** %5
%17 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %16, i32 0, i32 0
%18 = load i32, i32* %17
br label %19
19: ; preds = %15, %14
%20 = phi i32 [ 8, %14 ], [ %18, %15 ]
store i32 %20, i32* %9
%21 = load %struct.can_frame*, %struct.can_frame** %5
%22 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i32, i32* @CAN_ERR_FLAG
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = load %struct.can_frame*, %struct.can_frame** %5
%30 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = load i32, i32* @CAN_ERR_MASK
%33 = load i32, i32* @CAN_ERR_FLAG
%34 = or i32 %32, %33
%35 = and i32 %31, %34
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 9, i32* %8
br label %61
37: ; preds = %19
%38 = load %struct.can_frame*, %struct.can_frame** %5
%39 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = load i32, i32* @CAN_EFF_FLAG
%42 = and i32 %40, %41
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = load %struct.can_frame*, %struct.can_frame** %5
%47 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load i32, i32* @CAN_EFF_MASK
%50 = and i32 %48, %49
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %50)
store i32 9, i32* %8
br label %60
52: ; preds = %37
%53 = load i8*, i8** %4
%54 = load %struct.can_frame*, %struct.can_frame** %5
%55 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load i32, i32* @CAN_SFF_MASK
%58 = and i32 %56, %57
%59 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %58)
store i32 4, i32* %8
br label %60
60: ; preds = %52, %44
br label %61
61: ; preds = %60, %27
%62 = load %struct.can_frame*, %struct.can_frame** %5
%63 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %62, i32 0, i32 1
%64 = load i32, i32* %63
%65 = load i32, i32* @CAN_RTR_FLAG
%66 = and i32 %64, %65
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %61
%69 = load i8*, i8** %4
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %113
74: ; preds = %61
store i32 0, i32* %7
br label %75
75: ; preds = %109, %74
%76 = load i32, i32* %7
%77 = load i32, i32* %9
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %112
79: ; preds = %75
%80 = load i8*, i8** %4
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load %struct.can_frame*, %struct.can_frame** %5
%85 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %84, i32 0, i32 2
%86 = load i32*, i32** %85
%87 = load i32, i32* %7
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %86, i64 %88
%90 = load i32, i32* %89
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %83, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %8
%93 = add nsw i32 %92, 2
store i32 %93, i32* %8
%94 = load i32, i32* %6
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %108
96: ; preds = %79
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 1
%99 = load i32, i32* %9
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %108
101: ; preds = %96
%102 = load i8*, i8** %4
%103 = load i32, i32* %8
%104 = add nsw i32 %103, 1
store i32 %104, i32* %8
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds i8, i8* %102, i64 %105
%107 = call i32 (i8*, i8*, ...) @sprintf(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %108
108: ; preds = %101, %96, %79
br label %109
109: ; preds = %108
%110 = load i32, i32* %7
%111 = add nsw i32 %110, 1
store i32 %111, i32* %7
br label %75
112: ; preds = %75
br label %113
113: ; preds = %112, %68
ret void
}

LLVM IR (-O2):
%struct.can_frame = type { i32, i32, i32* }
@CAN_ERR_FLAG = global i32 0
@.str = [6 x i8] c"%08X#\00"
@CAN_ERR_MASK = global i32 0
@CAN_EFF_FLAG = global i32 0
@CAN_EFF_MASK = global i32 0
@.str.1 = [6 x i8] c"%03X#\00"
@CAN_SFF_MASK = global i32 0
@CAN_RTR_FLAG = global i32 0
@.str.3 = [5 x i8] c"%02X\00"
define void @sprint_canframe(i8* nocapture writeonly %0, %struct.can_frame* nocapture %1, i32 %2) {
%4 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp slt i32 %5, 8
%7 = select i1 %6, i32 %5, i32 8
%8 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = load i32, i32* @CAN_ERR_FLAG
%11 = and i32 %10, %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* @CAN_ERR_MASK
%15 = or i32 %14, %10
br label %24
16: ; preds = %3
%17 = load i32, i32* @CAN_EFF_FLAG
%18 = and i32 %17, %9
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = load i32, i32* @CAN_EFF_MASK
br label %24
22: ; preds = %16
%23 = load i32, i32* @CAN_SFF_MASK
br label %24
24: ; preds = %20, %22, %13
%25 = phi i32 [ %21, %20 ], [ %23, %22 ], [ %15, %13 ]
%26 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %20 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %22 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %13 ]
%27 = phi i32 [ 9, %20 ], [ 4, %22 ], [ 9, %13 ]
%28 = and i32 %25, %9
%29 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %26, i32 %28)
%30 = load i32, i32* %8
%31 = load i32, i32* @CAN_RTR_FLAG
%32 = and i32 %31, %30
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %24
%35 = icmp sgt i32 %5, 0
br i1 %35, label %36, label %67
36: ; preds = %34
%37 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 2
%38 = icmp ne i32 %2, 0
%39 = sext i32 %7 to i64
%40 = call i32 @llvm.smax.i32(i32 %7, i32 1)
%41 = zext i32 %40 to i64
br label %46
42: ; preds = %24
%43 = zext i32 %27 to i64
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = bitcast i8* %44 to i16*
store i16 82, i16* %45
br label %67
46: ; preds = %36, %64
%47 = phi i64 [ 0, %36 ], [ %56, %64 ]
%48 = phi i32 [ %27, %36 ], [ %65, %64 ]
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %0, i64 %49
%51 = load i32*, i32** %37
%52 = getelementptr inbounds i32, i32* %51, i64 %47
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %50, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = add nsw i32 %48, 2
%56 = add nuw nsw i64 %47, 1
%57 = icmp slt i64 %56, %39
%58 = select i1 %38, i1 %57, i1 false
br i1 %58, label %59, label %64
59: ; preds = %46
%60 = add nsw i32 %48, 3
%61 = sext i32 %55 to i64
%62 = getelementptr inbounds i8, i8* %0, i64 %61
%63 = bitcast i8* %62 to i16*
store i16 46, i16* %63
br label %64
64: ; preds = %46, %59
%65 = phi i32 [ %60, %59 ], [ %55, %46 ]
%66 = icmp eq i64 %56, %41
br i1 %66, label %67, label %46
67: ; preds = %64, %34, %42
ret void
}