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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printf_btr_ti_hecc(struct can_bittiming *bt, bool hdr) {
  if (hdr) {
    printf("%10s", "CANBTC");
  } else {
    uint32_t can_btc;
    can_btc = (bt->phase_seg2 - 1) & 0x7;
    can_btc |= ((bt->phase_seg1 + bt->prop_seg - 1) & 0xF) << 3;
    can_btc |= ((bt->sjw - 1) & 0x3) << 8;
    can_btc |= ((bt->brp - 1) & 0xFF) << 16;
    printf("0x%08x", can_btc);
  }
}


x86 assembly (clang, -O0):
<printf_btr_ti_hecc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1143 <printf_btr_ti_hecc+0x33>
lea    0xed0(%rip),%rdi
lea    0xece(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <printf_btr_ti_hecc+0x9e>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
and    $0x7,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x8(%rcx),%eax
sub    $0x1,%eax
and    $0xf,%eax
shl    $0x3,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
sub    $0x1,%eax
and    $0x3,%eax
shl    $0x8,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
sub    $0x1,%eax
and    $0xff,%eax
shl    $0x10,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_btr_ti_hecc>:
test   %esi,%esi
je     1129 <printf_btr_ti_hecc+0x19>
lea    0xee5(%rip),%rdi
lea    0xee3(%rip),%rsi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    (%rdi),%eax
mov    0x8(%rdi),%ecx
add    $0xffffffff,%eax
add    0x4(%rdi),%ecx
and    $0x7,%eax
lea    0x78(,%rcx,8),%ecx
and    $0x78,%ecx
or     %eax,%ecx
mov    0xc(%rdi),%eax
shl    $0x8,%eax
add    $0x300,%eax
and    $0x300,%eax
or     %ecx,%eax
mov    0x10(%rdi),%esi
shl    $0x10,%esi
add    $0xff0000,%esi
and    $0xff0000,%esi
or     %eax,%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

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

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