#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 */
unsigned char *get_ram(int);
int /*<<< orphan*/ printf(char *);
int write(int, unsigned char *, int);
int dump_ram(int f, int o) {
  int bytes;
  unsigned char *ram;
  ram = get_ram(f);
  if (ram == NULL)
    return 0;
  bytes = write(o, ram, 0x880);
  if (bytes != 0x880) {
    printf("FATAL ERROR: file write failed.\n");
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<dump_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <get_ram@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <dump_ram+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <dump_ram+0x71>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x880,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x880,-0x10(%rbp)
je     119a <dump_ram+0x6a>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <dump_ram+0x71>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ram>:
push   %rbx
mov    %esi,%ebx
call   1050 <get_ram@plt>
mov    %rax,%rsi
xor    %eax,%eax
test   %rsi,%rsi
je     116b <dump_ram+0x3b>
mov    %ebx,%edi
mov    $0x880,%edx
call   1040 <write@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x880,%ecx
je     116b <dump_ram+0x3b>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"FATAL ERROR: file write failed.\0A\00"
define i32 @dump_ram(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i8* @get_ram(i32 %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %22
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i8*, i8** %7
%16 = call i32 @write(i32 %14, i8* %15, i32 2176)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 2176
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %22
21: ; preds = %13
store i32 1, i32* %3
br label %22
22: ; preds = %21, %19, %12
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@str = [32 x i8] c"FATAL ERROR: file write failed.\00"
define i32 @dump_ram(i32 %0, i32 %1) {
%3 = tail call i8* @get_ram(i32 %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @write(i32 %1, i8* %3, i32 2176)
%7 = icmp eq i32 %6, 2176
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ 0, %8 ], [ 0, %2 ], [ 1, %5 ]
ret i32 %11
}