#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 unsigned int uint32_t;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, unsigned int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int dump(int fd, char fname[256], uint32_t start, uint32_t size) {
  unsigned int i;
  char c;
  int fdest = open(fname, O_WRONLY | O_CREAT | O_TRUNC,
                   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (fdest == -1)
    return 1;
  lseek(fd, start, SEEK_SET);
  for (i = 0; i < size; i++) {
    read(fd, &c, 1);
    write(fdest, &c, 1);
  }
  close(fdest);
  return 0;
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
mov    0x2e6e(%rip),%rax
or     (%rax),%esi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    0x2e44(%rip),%rax
or     (%rax),%edx
mov    0x2e23(%rip),%rax
or     (%rax),%edx
mov    0x2e12(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11c6 <dump+0x76>
movl   $0x1,-0x4(%rbp)
jmp    122c <dump+0xdc>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    121d <dump+0xcd>
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x24(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e1 <dump+0x91>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e3d(%rip),%rbp
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
or     0x0(%rbp),%eax
mov    0x2e7a(%rip),%rbp
or     0x0(%rbp),%eax
mov    0x2e30(%rip),%rbx
mov    0x2e51(%rip),%rbp
mov    0x0(%rbp),%ebp
or     (%rbx),%ebp
mov    0x2e2d(%rip),%rbx
or     (%rbx),%ebp
mov    %ecx,%ebx
mov    %edx,%r12d
mov    %edi,%r14d
mov    0x2e14(%rip),%rcx
or     (%rcx),%ebp
mov    %rsi,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1211 <dump+0xc1>
mov    %eax,%r15d
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %r12d,%esi
call   1040 <lseek@plt>
test   %ebx,%ebx
je     1205 <dump+0xb5>
lea    0xf(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
jne    11e0 <dump+0x90>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1216 <dump+0xc6>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@SEEK_SET = global i32 0
define i32 @dump(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i8*, i8** %7
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRUSR
%20 = load i32, i32* @S_IWUSR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IRGRP
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IROTH
%25 = or i32 %23, %24
%26 = call i32 @open(i8* %13, i32 %18, i32 %25)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %4
store i32 1, i32* %5
br label %50
30: ; preds = %4
%31 = load i32, i32* %6
%32 = load i32, i32* %8
%33 = load i32, i32* @SEEK_SET
%34 = call i32 @lseek(i32 %31, i32 %32, i32 %33)
store i32 0, i32* %10
br label %35
35: ; preds = %44, %30
%36 = load i32, i32* %10
%37 = load i32, i32* %9
%38 = icmp ult i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = load i32, i32* %6
%41 = call i32 @read(i32 %40, i8* %11, i32 1)
%42 = load i32, i32* %12
%43 = call i32 @write(i32 %42, i8* %11, i32 1)
br label %44
44: ; preds = %39
%45 = load i32, i32* %10
%46 = add i32 %45, 1
store i32 %46, i32* %10
br label %35
47: ; preds = %35
%48 = load i32, i32* %12
%49 = call i32 @close(i32 %48)
store i32 0, i32* %5
br label %50
50: ; preds = %47, %29
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@SEEK_SET = global i32 0
define i32 @dump(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = alloca i8
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = tail call i32 @open(i8* %1, i32 %10, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %32, label %20
20: ; preds = %4
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @lseek(i32 %0, i32 %2, i32 %21)
%23 = icmp eq i32 %3, 0
br i1 %23, label %30, label %24
24: ; preds = %20, %24
%25 = phi i32 [ %28, %24 ], [ 0, %20 ]
%26 = call i32 @read(i32 %0, i8* %5, i32 1)
%27 = call i32 @write(i32 %18, i8* %5, i32 1)
%28 = add nuw i32 %25, 1
%29 = icmp eq i32 %28, %3
br i1 %29, label %30, label %24
30: ; preds = %24, %20
%31 = tail call i32 @close(i32 %18)
br label %32
32: ; preds = %4, %30
%33 = phi i32 [ 0, %30 ], [ 1, %4 ]
ret i32 %33
}