#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;
};
struct middma_device {
  int dummy;
};
struct device {
  int dummy;
};

/* Variables and functions */
struct pci_dev *kmalloc(unsigned long);
scalar_t__ kzalloc(unsigned long);
int /*<<< orphan*/ mid_setup_dma(struct pci_dev *);
int /*<<< orphan*/ pci_set_drvdata(struct pci_dev *, struct middma_device *);
int main(void) {
  struct middma_device *device;
  struct device *tmp_dev;
  unsigned int base_addr;
  struct pci_dev *pdev = kmalloc(2976UL);
  if (pdev == 0) {
    return 0;
  }
  device = (struct middma_device *)kzalloc(1328UL);
  if (device == 0) {
    return 0;
  }
  pci_set_drvdata(pdev, device);
  mid_setup_dma(pdev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xba0,%edi
call   1060 <kmalloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1174 <main+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <main+0x76>
mov    $0x530,%edi
call   1030 <kzalloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x59>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <main+0x76>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <pci_set_drvdata@plt>
mov    -0x28(%rbp),%rdi
call   1050 <mid_setup_dma@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xba0,%edi
call   1060 <kmalloc@plt>
test   %rax,%rax
je     1175 <main+0x35>
mov    %rax,%rbx
mov    $0x530,%edi
call   1030 <kzalloc@plt>
test   %rax,%rax
je     1175 <main+0x35>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <pci_set_drvdata@plt>
mov    %rbx,%rdi
call   1050 <mid_setup_dma@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.middma_device = type { i32 }
%struct.device = type { i32 }
%struct.pci_dev = type { i32 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.middma_device*
%3 = alloca %struct.device*
%4 = alloca i32
%5 = alloca %struct.pci_dev*
store i32 0, i32* %1
%6 = call %struct.pci_dev* @kmalloc(i64 2976)
store %struct.pci_dev* %6, %struct.pci_dev** %5
%7 = load %struct.pci_dev*, %struct.pci_dev** %5
%8 = icmp eq %struct.pci_dev* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 0, i32* %1
br label %22
10: ; preds = %0
%11 = call i64 @kzalloc(i64 1328)
%12 = inttoptr i64 %11 to %struct.middma_device*
store %struct.middma_device* %12, %struct.middma_device** %2
%13 = load %struct.middma_device*, %struct.middma_device** %2
%14 = icmp eq %struct.middma_device* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 0, i32* %1
br label %22
16: ; preds = %10
%17 = load %struct.pci_dev*, %struct.pci_dev** %5
%18 = load %struct.middma_device*, %struct.middma_device** %2
%19 = call i32 @pci_set_drvdata(%struct.pci_dev* %17, %struct.middma_device* %18)
%20 = load %struct.pci_dev*, %struct.pci_dev** %5
%21 = call i32 @mid_setup_dma(%struct.pci_dev* %20)
store i32 0, i32* %1
br label %22
22: ; preds = %16, %15, %9
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.device = type { i32 }
%struct.pci_dev = type { i32 }
%struct.middma_device = type { i32 }
define i32 @main() {
%1 = tail call %struct.pci_dev* @kmalloc(i64 2976)
%2 = icmp eq %struct.pci_dev* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i64 @kzalloc(i64 1328)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = inttoptr i64 %4 to %struct.middma_device*
%8 = tail call i32 @pci_set_drvdata(%struct.pci_dev* %1, %struct.middma_device* %7)
%9 = tail call i32 @mid_setup_dma(%struct.pci_dev* %1)
br label %10
10: ; preds = %3, %0, %6
ret i32 0
}