#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void ddr_list_print() {
  printf("Enter ddr print\n");
  int fd;
  fd = open("/dev/hapara_ddr_malloc", O_RDWR);
  if (fd == -1)
    return;
  ioctl(fd, _IO('d', 2));
  close(fd);
  printf("Leave ddr print\n");
}


x86 assembly (clang, -O0):
<ddr_list_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    118b <ddr_list_print+0x3b>
jmp    11be <ddr_list_print+0x6e>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x64,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    -0x8(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddr_list_print>:
push   %rbx
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11a5 <ddr_list_print+0x55>
mov    %eax,%ebx
mov    $0x64,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe88(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter ddr print\0A\00"
@.str.1 = [23 x i8] c"/dev/hapara_ddr_malloc\00"
@O_RDWR = global i32 0
@.str.2 = [17 x i8] c"Leave ddr print\0A\00"
define void @ddr_list_print() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %0
br label %15
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 @_IO(i8 signext 100, i32 2)
%11 = call i32 @ioctl(i32 %9, i32 %10)
%12 = load i32, i32* %1
%13 = call i32 @close(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"/dev/hapara_ddr_malloc\00"
@O_RDWR = global i32 0
@str = [16 x i8] c"Enter ddr print\00"
@str.3 = [16 x i8] c"Leave ddr print\00"
define void @ddr_list_print() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = tail call i32 @_IO(i8 signext 100, i32 2)
%7 = tail call i32 @ioctl(i32 %3, i32 %6)
%8 = tail call i32 @close(i32 %3)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
br label %10
10: ; preds = %0, %5
ret void
}