#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 brp;
  int sjw;
  int prop_seg;
  int phase_seg1;
  int phase_seg2;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printf_btr_sja1000(struct can_bittiming *bt, bool hdr) {
  uint8_t btr0, btr1;
  if (hdr) {
    printf("BTR0 BTR1");
  } else {
    btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
    btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
           (((bt->phase_seg2 - 1) & 0x7) << 4);
    printf("0x%02x 0x%02x", btr0, btr1);
  }
}


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

x86 assembly (clang, -O2):
test   %esi,%esi
je     1122 <printf_btr_sja1000+0x12>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
add    $0xffffffff,%eax
and    $0x3f,%eax
shl    $0x6,%ecx
add    $0xc0,%ecx
movzbl %cl,%esi
or     %eax,%esi
mov    0x8(%rdi),%eax
mov    0xc(%rdi),%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
and    $0xf,%eax
mov    0x10(%rdi),%edx
shl    $0x4,%edx
add    $0x70,%edx
and    $0x70,%edx
or     %eax,%edx
lea    0xeac(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
%struct.can_bittiming = type { i32, i32, i32, i32, i32 }
@.str = [10 x i8] c"BTR0 BTR1\00"
@.str.1 = [14 x i8] c"0x%02x 0x%02x\00"
define void @printf_btr_sja1000(%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 ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %31
6: ; preds = %2
%7 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add i32 %8, 63
%10 = and i32 %9, 63
%11 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = shl i32 %12, 6
%14 = add i32 %13, 192
%15 = and i32 %14, 192
%16 = or i32 %15, %10
%17 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 3
%20 = load i32, i32* %19
%21 = add i32 %18, 15
%22 = add i32 %21, %20
%23 = and i32 %22, 15
%24 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 4
%25 = load i32, i32* %24
%26 = shl i32 %25, 4
%27 = add i32 %26, 112
%28 = and i32 %27, 112
%29 = or i32 %28, %23
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %29)
br label %31
31: ; preds = %6, %4
ret void
}