#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 pci_dev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ pci_write_config_dword(struct pci_dev *, int,
                                          unsigned short);
void dma_imwr(struct pci_dev *pdev, unsigned int chn_num, unsigned int w_r,
              unsigned int done_addr, unsigned int abrt_addr,
              unsigned short int data) {
  if (w_r) {
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x33c), done_addr);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x340), 0x0);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x344), abrt_addr);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x348), 0x0);
    switch (chn_num) {
    case 0:
      pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x34c), data);
      break;
    case 1:
      pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x34c), (data << 16));
      break;
    default:
      break;
    }
  } else {
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2d0), done_addr);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2d4), 0x0);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2d8), abrt_addr);
    pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2dc), 0x0);
    switch (chn_num) {
    case 0:
      pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2e0), data);
      break;
    case 1:
      pci_write_config_dword(pdev, ((0x0 + 0x700) + 0x2e0), (data << 16));
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<dma_imwr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9w,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11e5 <dma_imwr+0xd5>
mov    -0x8(%rbp),%rdi
movzwl -0x14(%rbp),%edx
mov    $0xa3c,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa40,%esi
xor    %edx,%edx
mov    %edx,-0x24(%rbp)
call   1030 <pci_write_config_dword@plt>
mov    -0x8(%rbp),%rdi
movzwl -0x18(%rbp),%edx
mov    $0xa44,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rdi
mov    $0xa48,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11a7 <dma_imwr+0x97>
jmp    1196 <dma_imwr+0x86>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
je     11be <dma_imwr+0xae>
jmp    11db <dma_imwr+0xcb>
mov    -0x8(%rbp),%rdi
mov    $0xa4c,%esi
movzwl -0x1a(%rbp),%edx
call   1030 <pci_write_config_dword@plt>
jmp    11e0 <dma_imwr+0xd0>
mov    -0x8(%rbp),%rdi
movzwl -0x1a(%rbp),%eax
shl    $0x10,%eax
mov    $0xa4c,%esi
movzwl %ax,%edx
call   1030 <pci_write_config_dword@plt>
jmp    11e0 <dma_imwr+0xd0>
jmp    11e0 <dma_imwr+0xd0>
jmp    128f <dma_imwr+0x17f>
mov    -0x8(%rbp),%rdi
movzwl -0x14(%rbp),%edx
mov    $0x9d0,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0x8(%rbp),%rdi
mov    $0x9d4,%esi
xor    %edx,%edx
mov    %edx,-0x2c(%rbp)
call   1030 <pci_write_config_dword@plt>
mov    -0x8(%rbp),%rdi
movzwl -0x18(%rbp),%edx
mov    $0x9d8,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0x2c(%rbp),%edx
mov    -0x8(%rbp),%rdi
mov    $0x9dc,%esi
call   1030 <pci_write_config_dword@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     1251 <dma_imwr+0x141>
jmp    1240 <dma_imwr+0x130>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     1268 <dma_imwr+0x158>
jmp    1285 <dma_imwr+0x175>
mov    -0x8(%rbp),%rdi
mov    $0x9e0,%esi
movzwl -0x1a(%rbp),%edx
call   1030 <pci_write_config_dword@plt>
jmp    128a <dma_imwr+0x17a>
mov    -0x8(%rbp),%rdi
movzwl -0x1a(%rbp),%eax
shl    $0x10,%eax
mov    $0x9e0,%esi
movzwl %ax,%edx
call   1030 <pci_write_config_dword@plt>
jmp    128a <dma_imwr+0x17a>
jmp    128a <dma_imwr+0x17a>
jmp    128f <dma_imwr+0x17f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dma_imwr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8d,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
test   %edx,%edx
je     117e <dma_imwr+0x6e>
movzwl %cx,%edx
mov    %rbx,%rdi
mov    $0xa3c,%esi
call   1030 <pci_write_config_dword@plt>
mov    %rbx,%rdi
mov    $0xa40,%esi
xor    %edx,%edx
call   1030 <pci_write_config_dword@plt>
movzwl %bp,%edx
mov    %rbx,%rdi
mov    $0xa44,%esi
call   1030 <pci_write_config_dword@plt>
mov    %rbx,%rdi
mov    $0xa48,%esi
xor    %edx,%edx
call   1030 <pci_write_config_dword@plt>
cmp    $0x1,%r15d
je     11e0 <dma_imwr+0xd0>
test   %r15d,%r15d
jne    11d5 <dma_imwr+0xc5>
movzwl %r14w,%edx
mov    %rbx,%rdi
mov    $0xa4c,%esi
jmp    11f4 <dma_imwr+0xe4>
movzwl %cx,%edx
mov    %rbx,%rdi
mov    $0x9d0,%esi
call   1030 <pci_write_config_dword@plt>
mov    %rbx,%rdi
mov    $0x9d4,%esi
xor    %edx,%edx
call   1030 <pci_write_config_dword@plt>
movzwl %bp,%edx
mov    %rbx,%rdi
mov    $0x9d8,%esi
call   1030 <pci_write_config_dword@plt>
mov    %rbx,%rdi
mov    $0x9dc,%esi
xor    %edx,%edx
call   1030 <pci_write_config_dword@plt>
cmp    $0x1,%r15d
je     11ea <dma_imwr+0xda>
test   %r15d,%r15d
jne    11d5 <dma_imwr+0xc5>
movzwl %r14w,%edx
mov    %rbx,%rdi
mov    $0x9e0,%esi
jmp    11f4 <dma_imwr+0xe4>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0xa4c,%esi
jmp    11f2 <dma_imwr+0xe2>
mov    %rbx,%rdi
mov    $0x9e0,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <pci_write_config_dword@plt>

LLVM IR (-O0):
%struct.pci_dev = type { i32 }
define void @dma_imwr(%struct.pci_dev* %0, i32 %1, i32 %2, i32 %3, i32 %4, i16 zeroext %5) {
%7 = alloca %struct.pci_dev*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i16
store %struct.pci_dev* %0, %struct.pci_dev** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i16 %5, i16* %12
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %42
15: ; preds = %6
%16 = load %struct.pci_dev*, %struct.pci_dev** %7
%17 = load i32, i32* %10
%18 = trunc i32 %17 to i16
%19 = call i32 @pci_write_config_dword(%struct.pci_dev* %16, i32 2620, i16 zeroext %18)
%20 = load %struct.pci_dev*, %struct.pci_dev** %7
%21 = call i32 @pci_write_config_dword(%struct.pci_dev* %20, i32 2624, i16 zeroext 0)
%22 = load %struct.pci_dev*, %struct.pci_dev** %7
%23 = load i32, i32* %11
%24 = trunc i32 %23 to i16
%25 = call i32 @pci_write_config_dword(%struct.pci_dev* %22, i32 2628, i16 zeroext %24)
%26 = load %struct.pci_dev*, %struct.pci_dev** %7
%27 = call i32 @pci_write_config_dword(%struct.pci_dev* %26, i32 2632, i16 zeroext 0)
%28 = load i32, i32* %8
switch i32 %28, label %40 [
i32 0, label %29
i32 1, label %33
]
29: ; preds = %15
%30 = load %struct.pci_dev*, %struct.pci_dev** %7
%31 = load i16, i16* %12
%32 = call i32 @pci_write_config_dword(%struct.pci_dev* %30, i32 2636, i16 zeroext %31)
br label %41
33: ; preds = %15
%34 = load %struct.pci_dev*, %struct.pci_dev** %7
%35 = load i16, i16* %12
%36 = zext i16 %35 to i32
%37 = shl i32 %36, 16
%38 = trunc i32 %37 to i16
%39 = call i32 @pci_write_config_dword(%struct.pci_dev* %34, i32 2636, i16 zeroext %38)
br label %41
40: ; preds = %15
br label %41
41: ; preds = %40, %33, %29
br label %69
42: ; preds = %6
%43 = load %struct.pci_dev*, %struct.pci_dev** %7
%44 = load i32, i32* %10
%45 = trunc i32 %44 to i16
%46 = call i32 @pci_write_config_dword(%struct.pci_dev* %43, i32 2512, i16 zeroext %45)
%47 = load %struct.pci_dev*, %struct.pci_dev** %7
%48 = call i32 @pci_write_config_dword(%struct.pci_dev* %47, i32 2516, i16 zeroext 0)
%49 = load %struct.pci_dev*, %struct.pci_dev** %7
%50 = load i32, i32* %11
%51 = trunc i32 %50 to i16
%52 = call i32 @pci_write_config_dword(%struct.pci_dev* %49, i32 2520, i16 zeroext %51)
%53 = load %struct.pci_dev*, %struct.pci_dev** %7
%54 = call i32 @pci_write_config_dword(%struct.pci_dev* %53, i32 2524, i16 zeroext 0)
%55 = load i32, i32* %8
switch i32 %55, label %67 [
i32 0, label %56
i32 1, label %60
]
56: ; preds = %42
%57 = load %struct.pci_dev*, %struct.pci_dev** %7
%58 = load i16, i16* %12
%59 = call i32 @pci_write_config_dword(%struct.pci_dev* %57, i32 2528, i16 zeroext %58)
br label %68
60: ; preds = %42
%61 = load %struct.pci_dev*, %struct.pci_dev** %7
%62 = load i16, i16* %12
%63 = zext i16 %62 to i32
%64 = shl i32 %63, 16
%65 = trunc i32 %64 to i16
%66 = call i32 @pci_write_config_dword(%struct.pci_dev* %61, i32 2528, i16 zeroext %65)
br label %68
67: ; preds = %42
br label %68
68: ; preds = %67, %60, %56
br label %69
69: ; preds = %68, %41
ret void
}

LLVM IR (-O2):
%struct.pci_dev = type { i32 }
define void @dma_imwr(%struct.pci_dev* %0, i32 %1, i32 %2, i32 %3, i32 %4, i16 zeroext %5) {
%7 = icmp eq i32 %2, 0
%8 = trunc i32 %3 to i16
br i1 %7, label %19, label %9
9: ; preds = %6
%10 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2620, i16 zeroext %8)
%11 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2624, i16 zeroext 0)
%12 = trunc i32 %4 to i16
%13 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2628, i16 zeroext %12)
%14 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2632, i16 zeroext 0)
switch i32 %1, label %29 [
i32 0, label %15
i32 1, label %17
]
15: ; preds = %9
%16 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2636, i16 zeroext %5)
br label %29
17: ; preds = %9
%18 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2636, i16 zeroext 0)
br label %29
19: ; preds = %6
%20 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2512, i16 zeroext %8)
%21 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2516, i16 zeroext 0)
%22 = trunc i32 %4 to i16
%23 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2520, i16 zeroext %22)
%24 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2524, i16 zeroext 0)
switch i32 %1, label %29 [
i32 0, label %25
i32 1, label %27
]
25: ; preds = %19
%26 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2528, i16 zeroext %5)
br label %29
27: ; preds = %19
%28 = tail call i32 @pci_write_config_dword(%struct.pci_dev* %0, i32 2528, i16 zeroext 0)
br label %29
29: ; preds = %25, %27, %19, %15, %17, %9
ret void
}