#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 */
typedef int uint8_t;
struct can_bittiming {
  int sjw;
  int brp;
  int phase_seg1;
  int prop_seg;
  int phase_seg2;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printf_btr_mcp251x(struct can_bittiming *bt, bool hdr) {
  uint8_t cnf1, cnf2, cnf3;
  if (hdr) {
    printf("CNF1 CNF2 CNF3");
  } else {
    cnf1 = ((bt->sjw - 1) << 6) | (bt->brp - 1);
    cnf2 = 0x80 | ((bt->phase_seg1 - 1) << 3) | (bt->prop_seg - 1);
    cnf3 = bt->phase_seg2 - 1;
    printf("0x%02x 0x%02x 0x%02x", cnf1, cnf2, cnf3);
  }
}


x86 assembly (clang, -O0):
<printf_btr_mcp251x>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     113c <printf_btr_mcp251x+0x2c>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119c <printf_btr_mcp251x+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
shl    $0x6,%eax
mov    -0x8(%rbp),%rcx
mov    0x4(%rcx),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
sub    $0x1,%eax
shl    $0x3,%eax
or     $0x80,%eax
mov    -0x8(%rbp),%rcx
mov    0xc(%rcx),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_btr_mcp251x>:
test   %esi,%esi
je     1122 <printf_btr_mcp251x+0x12>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    (%rdi),%eax
mov    0x4(%rdi),%esi
shl    $0x6,%eax
add    $0xffffffc0,%eax
add    $0xffffffff,%esi
or     %eax,%esi
mov    0x8(%rdi),%eax
lea    -0x8(,%rax,8),%eax
mov    0xc(%rdi),%edx
add    $0xffffffff,%edx
or     %eax,%edx
or     $0x80,%edx
mov    0x10(%rdi),%ecx
add    $0xffffffff,%ecx
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.can_bittiming = type { i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"CNF1 CNF2 CNF3\00"
@.str.1 = [21 x i8] c"0x%02x 0x%02x 0x%02x\00"
define void @printf_btr_mcp251x(%struct.can_bittiming* %0, i32 %1) {
%3 = alloca %struct.can_bittiming*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.can_bittiming* %0, %struct.can_bittiming** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %42
12: ; preds = %2
%13 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%14 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %15, 1
%17 = shl i32 %16, 6
%18 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%19 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = sub nsw i32 %20, 1
%22 = or i32 %17, %21
store i32 %22, i32* %5
%23 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%24 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = sub nsw i32 %25, 1
%27 = shl i32 %26, 3
%28 = or i32 128, %27
%29 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%30 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %29, i32 0, i32 3
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, 1
%33 = or i32 %28, %32
store i32 %33, i32* %6
%34 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%35 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %34, i32 0, i32 4
%36 = load i32, i32* %35
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %7
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
br label %42
42: ; preds = %12, %10
ret void
}

LLVM IR (-O2):
%struct.can_bittiming = type { i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"CNF1 CNF2 CNF3\00"
@.str.1 = [21 x i8] c"0x%02x 0x%02x 0x%02x\00"
define void @printf_btr_mcp251x(%struct.can_bittiming* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %28
6: ; preds = %2
%7 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = shl i32 %8, 6
%10 = add i32 %9, -64
%11 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, -1
%14 = or i32 %10, %13
%15 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 2
%16 = load i32, i32* %15
%17 = shl i32 %16, 3
%18 = add i32 %17, -8
%19 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 3
%20 = load i32, i32* %19
%21 = add nsw i32 %20, -1
%22 = or i32 %21, %18
%23 = or i32 %22, 128
%24 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 4
%25 = load i32, i32* %24
%26 = add nsw i32 %25, -1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %23, i32 %26)
br label %28
28: ; preds = %6, %4
ret void
}