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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printf_btr_flexcan(struct can_bittiming *bt, bool hdr) {
  if (hdr) {
    printf("%10s", "CAN_CTRL");
  } else {
    uint32_t ctrl = (((bt->brp - 1) << 24) | ((bt->sjw - 1) << 22) |
                     ((bt->phase_seg1 - 1) << 19) |
                     ((bt->phase_seg2 - 1) << 16) | ((bt->prop_seg - 1) << 0));
    printf("0x%08x", ctrl);
  }
}


x86 assembly (clang, -O0):
<printf_btr_flexcan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1143 <printf_btr_flexcan+0x33>
lea    0xed0(%rip),%rdi
lea    0xece(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119f <printf_btr_flexcan+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
shl    $0x18,%eax
mov    -0x8(%rbp),%rcx
mov    0x4(%rcx),%ecx
sub    $0x1,%ecx
shl    $0x16,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%ecx
sub    $0x1,%ecx
shl    $0x13,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    0xc(%rcx),%ecx
sub    $0x1,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    0x10(%rcx),%ecx
sub    $0x1,%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_btr_flexcan>:
test   %esi,%esi
je     1129 <printf_btr_flexcan+0x19>
lea    0xf15(%rip),%rdi
lea    0xf13(%rip),%rsi
xor    %eax,%eax
jmp    1030 <printf@plt>
movdqu (%rdi),%xmm0
movdqa 0xecb(%rip),%xmm1
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm0
pmuludq 0xec5(%rip),%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
paddd  0xec4(%rip),%xmm1
mov    0x10(%rdi),%eax
add    $0xffffffff,%eax
pshufd $0xee,%xmm1,%xmm0
por    %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
por    %xmm0,%xmm1
movd   %xmm1,%esi
or     %eax,%esi
lea    0xebd(%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 = [9 x i8] c"CAN_CTRL\00"
@.str.2 = [7 x i8] c"0x%08x\00"
define void @printf_btr_flexcan(%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 ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %42
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 = shl i32 %14, 24
%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 = sub nsw i32 %18, 1
%20 = shl i32 %19, 22
%21 = or i32 %15, %20
%22 = load %struct.can_bittiming*, %struct.can_bittiming** %3
%23 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = sub nsw i32 %24, 1
%26 = shl i32 %25, 19
%27 = or i32 %21, %26
%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 = shl i32 %31, 16
%33 = or i32 %27, %32
%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
%38 = shl i32 %37, 0
%39 = or i32 %33, %38
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; 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 = [9 x i8] c"CAN_CTRL\00"
@.str.2 = [7 x i8] c"0x%08x\00"
define void @printf_btr_flexcan(%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 ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %17
6: ; preds = %2
%7 = bitcast %struct.can_bittiming* %0 to <4 x i32>*
%8 = load <4 x i32>, <4 x i32>* %7
%9 = shl <4 x i32> %8, <i32 24, i32 22, i32 19, i32 16>
%10 = add <4 x i32> %9, <i32 -16777216, i32 -4194304, i32 -524288, i32 -65536>
%11 = getelementptr inbounds %struct.can_bittiming, %struct.can_bittiming* %0, i64 0, i32 4
%12 = load i32, i32* %11
%13 = add nsw i32 %12, -1
%14 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %10)
%15 = or i32 %14, %13
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %6, %4
ret void
}