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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(struct SlaveInfo *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int get_title_from_slave(char *slave, char *title) {
  char Title[100];
  struct SlaveInfo {
    unsigned long Security;
    char ID[8];
    unsigned short Version;
    unsigned short Flags;
    unsigned long BaseMemSize;
    unsigned long ExecInstall;
    unsigned short GameLoader;
    unsigned short CurrentDir;
    unsigned short DontCache;
    char keydebug;
    char keyexit;
    unsigned long ExpMem;
    unsigned short name;
    unsigned short copy;
    unsigned short info;
  };
  struct SlaveInfo sl;
  FILE *fp = fopen(slave, "rbe");
  if (fp == NULL) {
    return 1;
  }
  fseek(fp, 32, SEEK_SET);
  fread(&sl, 1, sizeof(sl), fp);
  fseek(fp, sl.name + 32, SEEK_SET);
  if (sl.Version < 10) {
    return 1;
  }
  for (int i = 0; i <= 99; i++) {
    Title[i] = fgetc(fp);
    if (Title[i] == '\n') {
      Title[i] = '\0';
      break;
    }
  }
  strcpy(title, Title);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_title_from_slave>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    11a4 <get_title_from_slave+0x44>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <get_title_from_slave+0x145>
mov    -0xc8(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1070 <fseek@plt>
lea    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1040 <fread@plt>
mov    -0xc8(%rbp),%rdi
movzwl -0x88(%rbp),%esi
add    $0x20,%esi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
movzwl -0xb0(%rbp),%eax
cmp    $0xa,%eax
jge    1216 <get_title_from_slave+0xb6>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <get_title_from_slave+0x145>
movl   $0x0,-0xcc(%rbp)
cmpl   $0x63,-0xcc(%rbp)
jg     1285 <get_title_from_slave+0x125>
mov    -0xc8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,%cl
movslq -0xcc(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
movslq -0xcc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    126c <get_title_from_slave+0x10c>
movslq -0xcc(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
jmp    1285 <get_title_from_slave+0x125>
jmp    1271 <get_title_from_slave+0x111>
mov    -0xcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
jmp    1220 <get_title_from_slave+0xc0>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc8(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_title_from_slave>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%r14
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fc <get_title_from_slave+0x9c>
mov    %rax,%rbx
mov    0x2e55(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x20,%esi
call   1070 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movzwl 0x38(%rsp),%esi
add    $0x20,%esi
mov    (%r15),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
cmpw   $0xa,0x10(%rsp)
jb     121f <get_title_from_slave+0xbf>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %al,0x40(%rsp,%rbp,1)
cmp    $0xa,%al
je     1203 <get_title_from_slave+0xa3>
add    $0x1,%rbp
cmp    $0x64,%rbp
jne    11e0 <get_title_from_slave+0x80>
jmp    1208 <get_title_from_slave+0xa8>
mov    $0x1,%ebp
jmp    121f <get_title_from_slave+0xbf>
movb   $0x0,0x40(%rsp,%rbp,1)
lea    0x40(%rsp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.SlaveInfo = type { i64, [8 x i8], i16, i16, i64, i64, i16, i16, i16, i8, i8, i64, i16, i16, i16 }
%struct.SlaveInfo.0 = type opaque
@.str = [4 x i8] c"rbe\00"
@SEEK_SET = global i32 0
define i32 @get_title_from_slave(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [100 x i8]
%7 = alloca %struct.SlaveInfo
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %64
15: ; preds = %2
%16 = load i32*, i32** %8
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 32, i32 %17)
%19 = bitcast %struct.SlaveInfo* %7 to %struct.SlaveInfo.0*
%20 = load i32*, i32** %8
%21 = call i32 @fread(%struct.SlaveInfo.0* %19, i32 1, i32 64, i32* %20)
%22 = load i32*, i32** %8
%23 = getelementptr inbounds %struct.SlaveInfo, %struct.SlaveInfo* %7, i32 0, i32 12
%24 = load i16, i16* %23
%25 = zext i16 %24 to i32
%26 = add nsw i32 %25, 32
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %22, i32 %26, i32 %27)
%29 = getelementptr inbounds %struct.SlaveInfo, %struct.SlaveInfo* %7, i32 0, i32 2
%30 = load i16, i16* %29
%31 = zext i16 %30 to i32
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %34
33: ; preds = %15
store i32 1, i32* %3
br label %64
34: ; preds = %15
store i32 0, i32* %9
br label %35
35: ; preds = %55, %34
%36 = load i32, i32* %9
%37 = icmp sle i32 %36, 99
br i1 %37, label %38, label %58
38: ; preds = %35
%39 = load i32*, i32** %8
%40 = call signext i8 @fgetc(i32* %39)
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %42
store i8 %40, i8* %43
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 10
br i1 %49, label %50, label %54
50: ; preds = %38
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %52
store i8 0, i8* %53
br label %58
54: ; preds = %38
br label %55
55: ; preds = %54
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %35
58: ; preds = %50, %35
%59 = load i8*, i8** %5
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%61 = call i32 @strcpy(i8* %59, i8* %60)
%62 = load i32*, i32** %8
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %58, %33, %14
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.SlaveInfo = type { i64, [8 x i8], i16, i16, i64, i64, i16, i16, i16, i8, i8, i64, i16, i16, i16 }
%struct.SlaveInfo.0 = type opaque
@.str = [4 x i8] c"rbe\00"
@SEEK_SET = global i32 0
define i32 @get_title_from_slave(i8* nocapture %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = alloca %struct.SlaveInfo
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.SlaveInfo* %4 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %37, label %9
9: ; preds = %2
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %7, i32 32, i32 %10)
%12 = bitcast %struct.SlaveInfo* %4 to %struct.SlaveInfo.0*
%13 = call i32 @fread(%struct.SlaveInfo.0* %12, i32 1, i32 64, i32* %7)
%14 = getelementptr inbounds %struct.SlaveInfo, %struct.SlaveInfo* %4, i64 0, i32 12
%15 = load i16, i16* %14
%16 = zext i16 %15 to i32
%17 = add nuw nsw i32 %16, 32
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %7, i32 %17, i32 %18)
%20 = getelementptr inbounds %struct.SlaveInfo, %struct.SlaveInfo* %4, i64 0, i32 2
%21 = load i16, i16* %20
%22 = icmp ult i16 %21, 10
br i1 %22, label %37, label %23
23: ; preds = %9, %31
%24 = phi i64 [ %32, %31 ], [ 0, %9 ]
%25 = tail call signext i8 @fgetc(i32* %7)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %24
store i8 %25, i8* %26
%27 = icmp eq i8 %25, 10
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = and i64 %24, 4294967295
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %29
store i8 0, i8* %30
br label %34
31: ; preds = %23
%32 = add nuw nsw i64 %24, 1
%33 = icmp eq i64 %32, 100
br i1 %33, label %34, label %23
34: ; preds = %31, %28
%35 = call i32 @strcpy(i8* %1, i8* %5)
%36 = call i32 @fclose(i32* %7)
br label %37
37: ; preds = %9, %2, %34
%38 = phi i32 [ 0, %34 ], [ 1, %2 ], [ 1, %9 ]
ret i32 %38
}