#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 maxdlen) {
  int i, offset;
  int len = (cf->can_dlc > maxdlen) ? maxdlen : 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) {
    if (cf->can_dlc)
      sprintf(buf + offset, "R%d", cf->can_dlc);
    else
      sprintf(buf + offset, "R");
    return;
  }
  for (i = 0; i < len; i++) {
    sprintf(buf + offset, "%02X", cf->data[i]);
    offset += 2;
    if (sep && (i + 1 < len))
      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    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x18(%rbp),%eax
jle    1140 <sprint_canframe+0x30>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1149 <sprint_canframe+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2e8b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a1 <sprint_canframe+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    0x2e65(%rip),%rcx
or     (%rcx),%eax
and    %eax,%edx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x9,-0x20(%rbp)
jmp    1216 <sprint_canframe+0x106>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2e19(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e8 <sprint_canframe+0xd8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2e14(%rip),%rax
and    (%rax),%edx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x9,-0x20(%rbp)
jmp    1211 <sprint_canframe+0x101>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    0x2db6(%rip),%rax
and    (%rax),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x4,-0x20(%rbp)
jmp    1216 <sprint_canframe+0x106>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d9c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     127e <sprint_canframe+0x16e>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     1260 <sprint_canframe+0x150>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1279 <sprint_canframe+0x169>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1310 <sprint_canframe+0x200>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1310 <sprint_canframe+0x200>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12fd <sprint_canframe+0x1ed>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x24(%rbp),%eax
jge    12fd <sprint_canframe+0x1ed>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
cltq
add    %rax,%rdi
lea    0xd21(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1302 <sprint_canframe+0x1f2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1285 <sprint_canframe+0x175>
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,%r14
mov    %rdi,%rbx
mov    (%rsi),%r15d
cmp    %ecx,%r15d
cmovg  %ecx,%r15d
mov    0x4(%rsi),%eax
mov    0x2eac(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
je     114d <sprint_canframe+0x3d>
mov    0x2e8f(%rip),%rcx
or     (%rcx),%edx
jmp    1165 <sprint_canframe+0x55>
mov    0x2e74(%rip),%rcx
test   %eax,(%rcx)
je     1248 <sprint_canframe+0x138>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%edx
mov    $0x9,%ebp
lea    0xe8f(%rip),%rsi
and    %eax,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
test   %eax,0x4(%r14)
je     11bb <sprint_canframe+0xab>
mov    (%r14),%edx
mov    %ebp,%eax
add    %rax,%rbx
test   %edx,%edx
je     1234 <sprint_canframe+0x124>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sprintf@plt>
test   %r15d,%r15d
jle    1239 <sprint_canframe+0x129>
mov    %r15d,%r13d
mov    %r13,0x10(%rsp)
neg    %r13
mov    $0x1,%r12d
jmp    11f5 <sprint_canframe+0xe5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r12
mov    %r15d,%ebp
cmp    $0x1,%rax
je     1239 <sprint_canframe+0x129>
movslq %ebp,%r15
lea    (%rbx,%r15,1),%rdi
mov    0x8(%r14),%rax
mov    -0x4(%rax,%r12,4),%edx
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%r15
cmpl   $0x0,0xc(%rsp)
je     11e0 <sprint_canframe+0xd0>
cmp    0x10(%rsp),%r12
jae    11e0 <sprint_canframe+0xd0>
add    $0x3,%ebp
movw   $0x2e,(%rbx,%r15,1)
mov    %ebp,%r15d
jmp    11e0 <sprint_canframe+0xd0>
movw   $0x52,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d61(%rip),%rcx
mov    (%rcx),%edx
mov    $0x4,%ebp
lea    0xda9(%rip),%rsi
jmp    1171 <sprint_canframe+0x61>

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 = [4 x i8] c"R%d\00"
@.str.3 = [2 x i8] c"R\00"
@.str.4 = [5 x i8] c"%02X\00"
@.str.5 = [2 x i8] c".\00"
define void @sprint_canframe(i8* %0, %struct.can_frame* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca %struct.can_frame*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store %struct.can_frame* %1, %struct.can_frame** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load %struct.can_frame*, %struct.can_frame** %6
%13 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* %8
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %8
br label %23
19: ; preds = %4
%20 = load %struct.can_frame*, %struct.can_frame** %6
%21 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %20, i32 0, i32 0
%22 = load i32, i32* %21
br label %23
23: ; preds = %19, %17
%24 = phi i32 [ %18, %17 ], [ %22, %19 ]
store i32 %24, i32* %11
%25 = load %struct.can_frame*, %struct.can_frame** %6
%26 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i32, i32* @CAN_ERR_FLAG
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %23
%32 = load i8*, i8** %5
%33 = load %struct.can_frame*, %struct.can_frame** %6
%34 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load i32, i32* @CAN_ERR_MASK
%37 = load i32, i32* @CAN_ERR_FLAG
%38 = or i32 %36, %37
%39 = and i32 %35, %38
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %39)
store i32 9, i32* %10
br label %65
41: ; preds = %23
%42 = load %struct.can_frame*, %struct.can_frame** %6
%43 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %42, i32 0, i32 1
%44 = load i32, i32* %43
%45 = load i32, i32* @CAN_EFF_FLAG
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %41
%49 = load i8*, i8** %5
%50 = load %struct.can_frame*, %struct.can_frame** %6
%51 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load i32, i32* @CAN_EFF_MASK
%54 = and i32 %52, %53
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %54)
store i32 9, i32* %10
br label %64
56: ; preds = %41
%57 = load i8*, i8** %5
%58 = load %struct.can_frame*, %struct.can_frame** %6
%59 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = load i32, i32* @CAN_SFF_MASK
%62 = and i32 %60, %61
%63 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %62)
store i32 4, i32* %10
br label %64
64: ; preds = %56, %48
br label %65
65: ; preds = %64, %31
%66 = load %struct.can_frame*, %struct.can_frame** %6
%67 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = load i32, i32* @CAN_RTR_FLAG
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %93
72: ; preds = %65
%73 = load %struct.can_frame*, %struct.can_frame** %6
%74 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %86
77: ; preds = %72
%78 = load i8*, i8** %5
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load %struct.can_frame*, %struct.can_frame** %6
%83 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %84)
br label %92
86: ; preds = %72
%87 = load i8*, i8** %5
%88 = load i32, i32* %10
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %92
92: ; preds = %86, %77
br label %131
93: ; preds = %65
store i32 0, i32* %9
br label %94
94: ; preds = %128, %93
%95 = load i32, i32* %9
%96 = load i32, i32* %11
%97 = icmp slt i32 %95, %96
br i1 %97, label %98, label %131
98: ; preds = %94
%99 = load i8*, i8** %5
%100 = load i32, i32* %10
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
%103 = load %struct.can_frame*, %struct.can_frame** %6
%104 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %103, i32 0, i32 2
%105 = load i32*, i32** %104
%106 = load i32, i32* %9
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = load i32, i32* %108
%110 = call i32 (i8*, i8*, ...) @sprintf(i8* %102, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %109)
%111 = load i32, i32* %10
%112 = add nsw i32 %111, 2
store i32 %112, i32* %10
%113 = load i32, i32* %7
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %127
115: ; preds = %98
%116 = load i32, i32* %9
%117 = add nsw i32 %116, 1
%118 = load i32, i32* %11
%119 = icmp slt i32 %117, %118
br i1 %119, label %120, label %127
120: ; preds = %115
%121 = load i8*, i8** %5
%122 = load i32, i32* %10
%123 = add nsw i32 %122, 1
store i32 %123, i32* %10
%124 = sext i32 %122 to i64
%125 = getelementptr inbounds i8, i8* %121, i64 %124
%126 = call i32 (i8*, i8*, ...) @sprintf(i8* %125, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %127
127: ; preds = %120, %115, %98
br label %128
128: ; preds = %127
%129 = load i32, i32* %9
%130 = add nsw i32 %129, 1
store i32 %130, i32* %9
br label %94
131: ; preds = %92, %94
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.2 = [4 x i8] c"R%d\00"
@.str.4 = [5 x i8] c"%02X\00"
define void @sprint_canframe(i8* nocapture writeonly %0, %struct.can_frame* nocapture %1, i32 %2, i32 %3) {
%5 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp sgt i32 %6, %3
%8 = select i1 %7, i32 %3, i32 %6
%9 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = load i32, i32* @CAN_ERR_FLAG
%12 = and i32 %11, %10
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i32, i32* @CAN_ERR_MASK
%16 = or i32 %15, %11
br label %25
17: ; preds = %4
%18 = load i32, i32* @CAN_EFF_FLAG
%19 = and i32 %18, %10
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = load i32, i32* @CAN_EFF_MASK
br label %25
23: ; preds = %17
%24 = load i32, i32* @CAN_SFF_MASK
br label %25
25: ; preds = %21, %23, %14
%26 = phi i32 [ %22, %21 ], [ %24, %23 ], [ %16, %14 ]
%27 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %21 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %23 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %14 ]
%28 = phi i32 [ 9, %21 ], [ 4, %23 ], [ 9, %14 ]
%29 = and i32 %26, %10
%30 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %27, i32 %29)
%31 = load i32, i32* %9
%32 = load i32, i32* @CAN_RTR_FLAG
%33 = and i32 %32, %31
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %25
%36 = icmp sgt i32 %8, 0
br i1 %36, label %37, label %72
37: ; preds = %35
%38 = getelementptr inbounds %struct.can_frame, %struct.can_frame* %1, i64 0, i32 2
%39 = icmp ne i32 %2, 0
%40 = zext i32 %8 to i64
%41 = zext i32 %8 to i64
br label %51
42: ; preds = %25
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 0
%45 = zext i32 %28 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
br i1 %44, label %49, label %47
47: ; preds = %42
%48 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %72
49: ; preds = %42
%50 = bitcast i8* %46 to i16*
store i16 82, i16* %50
br label %72
51: ; preds = %37, %69
%52 = phi i64 [ 0, %37 ], [ %61, %69 ]
%53 = phi i32 [ %28, %37 ], [ %70, %69 ]
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %0, i64 %54
%56 = load i32*, i32** %38
%57 = getelementptr inbounds i32, i32* %56, i64 %52
%58 = load i32, i32* %57
%59 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %55, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = add nsw i32 %53, 2
%61 = add nuw nsw i64 %52, 1
%62 = icmp ult i64 %61, %40
%63 = select i1 %39, i1 %62, i1 false
br i1 %63, label %64, label %69
64: ; preds = %51
%65 = add nsw i32 %53, 3
%66 = sext i32 %60 to i64
%67 = getelementptr inbounds i8, i8* %0, i64 %66
%68 = bitcast i8* %67 to i16*
store i16 46, i16* %68
br label %69
69: ; preds = %51, %64
%70 = phi i32 [ %65, %64 ], [ %60, %51 ]
%71 = icmp eq i64 %61, %41
br i1 %71, label %72, label %51
72: ; preds = %69, %35, %47, %49
ret void
}