#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(unsigned char *, int, unsigned short,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
unsigned char *malloc(unsigned short);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void process_data_seg(FILE *f, unsigned short ds) {
  long pos;
  unsigned short off = 0;
  unsigned char *p;
  unsigned char *pp;
  unsigned char *tempstr;
  tempstr = malloc(70 + 1);
  pos = ftell(f);
  pp = p = malloc(ds);
  fread(p, 1, ds, f);
  fseek(f, pos, SEEK_SET);
  while (off < ds) {
    int len;
    unsigned short localoff = 0;
    while ((len = (strlen((char *)pp) > 70)) ? 70 : strlen((char *)pp)) {
      memcpy(tempstr, pp, len);
      tempstr[len] = '\0';
      if (localoff)
        printf("\tdb\t\'%s\'\n", tempstr);
      else
        printf("%04X\tdb\t\'%s\'\n", off, tempstr);
      localoff += len;
      pp += len;
    }
    pp++;
    off += localoff + 1;
    printf("\tdb\t00\n");
  }
  free(p);
  free(tempstr);
}


x86 assembly (clang, -O0):
<process_data_seg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movw   $0x0,-0x1a(%rbp)
mov    $0x47,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x18(%rbp)
movzwl -0xa(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xa(%rbp),%ax
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
movzwl %ax,%edx
call   1040 <fread@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
movzwl -0x1a(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    12fd <process_data_seg+0x17d>
movw   $0x0,-0x3e(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x46,%eax
setg   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x3c(%rbp)
test   $0x1,%al
jne    1231 <process_data_seg+0xb1>
jmp    123e <process_data_seg+0xbe>
mov    $0x46,%eax
mov    %eax,-0x44(%rbp)
jmp    124a <process_data_seg+0xca>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    $0x0,%eax
je     12cd <process_data_seg+0x14d>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpw   $0x0,-0x3e(%rbp)
je     1294 <process_data_seg+0x114>
mov    -0x38(%rbp),%rsi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12aa <process_data_seg+0x12a>
movzwl -0x1a(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%ecx
movzwl -0x3e(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x3e(%rbp)
mov    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    120a <process_data_seg+0x8a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
movzwl -0x3e(%rbp),%ecx
add    $0x1,%ecx
movzwl -0x1a(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x1a(%rbp)
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11f4 <process_data_seg+0x74>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_data_seg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%rbp
mov    $0x47,%edi
call   10a0 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %rbp,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <fseek@plt>
mov    %ebx,0x14(%rsp)
test   %ebx,%ebx
je     12d8 <process_data_seg+0x148>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x18(%rsp),%r14
jmp    123d <process_data_seg+0xad>
nopl   0x0(%rax)
add    $0x1,%r14
mov    0x8(%rsp),%rax
lea    (%rax,%rbp,1),%ebx
add    $0x1,%ebx
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
movzwl %bx,%eax
mov    %rax,0x8(%rsp)
cmp    0x14(%rsp),%eax
jae    12d8 <process_data_seg+0x148>
xor    %ebp,%ebp
jmp    1274 <process_data_seg+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xda9(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
cmp    $0x47,%r15d
setge  %al
add    %eax,%ebp
add    %r13,%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
xor    %r12d,%r12d
cmp    $0x47,%eax
setge  %bl
jge    129a <process_data_seg+0x10a>
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
je     1210 <process_data_seg+0x80>
mov    %bl,%r12b
xor    %r13d,%r13d
cmp    $0x47,%r15d
setge  %r13b
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1090 <memcpy@plt>
movb   $0x0,(%rbx,%r13,1)
test   %bp,%bp
je     1250 <process_data_seg+0xc0>
lea    0xd38(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1266 <process_data_seg+0xd6>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [10 x i8] c"\09db\09'%s'\0A\00"
@.str.1 = [14 x i8] c"%04X\09db\09'%s'\0A\00"
@.str.2 = [8 x i8] c"\09db\0900\0A\00"
define void @process_data_seg(i32* %0, i16 zeroext %1) {
%3 = alloca i32*
%4 = alloca i16
%5 = alloca i64
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i16
store i32* %0, i32** %3
store i16 %1, i16* %4
store i16 0, i16* %6
%12 = call i8* @malloc(i16 zeroext 71)
store i8* %12, i8** %9
%13 = load i32*, i32** %3
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %5
%15 = load i16, i16* %4
%16 = call i8* @malloc(i16 zeroext %15)
store i8* %16, i8** %7
store i8* %16, i8** %8
%17 = load i8*, i8** %7
%18 = load i16, i16* %4
%19 = load i32*, i32** %3
%20 = call i32 @fread(i8* %17, i32 1, i16 zeroext %18, i32* %19)
%21 = load i32*, i32** %3
%22 = load i64, i64* %5
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %21, i64 %22, i32 %23)
br label %25
25: ; preds = %73, %2
%26 = load i16, i16* %6
%27 = zext i16 %26 to i32
%28 = load i16, i16* %4
%29 = zext i16 %28 to i32
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %84
31: ; preds = %25
store i16 0, i16* %11
br label %32
32: ; preds = %63, %31
%33 = load i8*, i8** %8
%34 = call i32 @strlen(i8* %33)
%35 = icmp sgt i32 %34, 70
%36 = zext i1 %35 to i32
store i32 %36, i32* %10
br i1 %35, label %37, label %38
37: ; preds = %32
br label %41
38: ; preds = %32
%39 = load i8*, i8** %8
%40 = call i32 @strlen(i8* %39)
br label %41
41: ; preds = %38, %37
%42 = phi i32 [ 70, %37 ], [ %40, %38 ]
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %73
44: ; preds = %41
%45 = load i8*, i8** %9
%46 = load i8*, i8** %8
%47 = load i32, i32* %10
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
%49 = load i8*, i8** %9
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i16, i16* %11
%54 = icmp ne i16 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %44
%56 = load i8*, i8** %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %56)
br label %63
58: ; preds = %44
%59 = load i16, i16* %6
%60 = zext i16 %59 to i32
%61 = load i8*, i8** %9
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %60, i8* %61)
br label %63
63: ; preds = %58, %55
%64 = load i32, i32* %10
%65 = load i16, i16* %11
%66 = zext i16 %65 to i32
%67 = add nsw i32 %66, %64
%68 = trunc i32 %67 to i16
store i16 %68, i16* %11
%69 = load i32, i32* %10
%70 = load i8*, i8** %8
%71 = sext i32 %69 to i64
%72 = getelementptr inbounds i8, i8* %70, i64 %71
store i8* %72, i8** %8
br label %32
73: ; preds = %41
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %8
%76 = load i16, i16* %11
%77 = zext i16 %76 to i32
%78 = add nsw i32 %77, 1
%79 = load i16, i16* %6
%80 = zext i16 %79 to i32
%81 = add nsw i32 %80, %78
%82 = trunc i32 %81 to i16
store i16 %82, i16* %6
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %25
84: ; preds = %25
%85 = load i8*, i8** %7
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %9
%88 = call i32 @free(i8* %87)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [10 x i8] c"\09db\09'%s'\0A\00"
@.str.1 = [14 x i8] c"%04X\09db\09'%s'\0A\00"
@str = [7 x i8] c"\09db\0900\00"
define void @process_data_seg(i32* nocapture %0, i16 zeroext %1) {
%3 = tail call i8* @malloc(i16 zeroext 71)
%4 = tail call i64 @ftell(i32* %0)
%5 = tail call i8* @malloc(i16 zeroext %1)
%6 = tail call i32 @fread(i8* %5, i32 1, i16 zeroext %1, i32* %0)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i64 %4, i32 %7)
%9 = zext i16 %1 to i32
%10 = icmp eq i16 %1, 0
br i1 %10, label %44, label %11
11: ; preds = %2, %36
%12 = phi i32 [ %42, %36 ], [ 0, %2 ]
%13 = phi i8* [ %37, %36 ], [ %5, %2 ]
br label %14
14: ; preds = %11, %32
%15 = phi i8* [ %35, %32 ], [ %13, %11 ]
%16 = phi i16 [ %34, %32 ], [ 0, %11 ]
%17 = tail call i32 @strlen(i8* %15)
%18 = icmp sgt i32 %17, 70
%19 = zext i1 %18 to i32
br i1 %18, label %23, label %20
20: ; preds = %14
%21 = tail call i32 @strlen(i8* %15)
%22 = icmp eq i32 %21, 0
br i1 %22, label %36, label %23
23: ; preds = %14, %20
%24 = tail call i32 @memcpy(i8* %3, i8* %15, i32 %19)
%25 = zext i1 %18 to i64
%26 = getelementptr inbounds i8, i8* %3, i64 %25
store i8 0, i8* %26
%27 = icmp eq i16 %16, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %32
30: ; preds = %23
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12, i8* %3)
br label %32
32: ; preds = %30, %28
%33 = zext i1 %18 to i16
%34 = add i16 %16, %33
%35 = getelementptr inbounds i8, i8* %15, i64 %25
br label %14
36: ; preds = %20
%37 = getelementptr inbounds i8, i8* %15, i64 1
%38 = zext i16 %16 to i32
%39 = add nuw nsw i32 %12, 1
%40 = add nuw nsw i32 %39, %38
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%42 = and i32 %40, 65535
%43 = icmp ult i32 %42, %9
br i1 %43, label %11, label %44
44: ; preds = %36, %2
%45 = tail call i32 @free(i8* %5)
%46 = tail call i32 @free(i8* %3)
ret void
}