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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ Unpack29_fileoutput(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ *tmpfile();
void Unpack29(FILE *inputfile, int DestUnpSize, int UnpPackedSize, int Flags) {
  FILE *ofile;
  static int i = 0;
  int c;
  char tmpfilename[100];
  extern unsigned char *temp_output_buffer;
  extern unsigned long *temp_output_buffer_offset;
  snprintf(tmpfilename, sizeof(tmpfilename) - 1, "/tmp/unrar_tmpf_%06d", i);
  i++;
  ofile = tmpfile();
  if (ofile == NULL) {
    return;
  }
  Unpack29_fileoutput(ofile, inputfile, DestUnpSize, UnpPackedSize, Flags);
  if (temp_output_buffer != NULL) {
    fseek(ofile, 0, SEEK_SET);
    while (!feof(ofile)) {
      if ((*temp_output_buffer_offset) > DestUnpSize) {
        break;
      }
      c = fgetc(ofile);
      if (c == EOF) {
        break;
      }
      temp_output_buffer[(*temp_output_buffer_offset)] = c;
      (*temp_output_buffer_offset)++;
    }
  }
  fclose(ofile);
}


x86 assembly (clang, -O0):
<Unpack29>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x90(%rbp),%rdi
mov    0x2ec7(%rip),%ecx
mov    $0x63,%esi
lea    0xe5f(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x2eb0(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ea7(%rip)
mov    $0x0,%al
call   1070 <tmpfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <Unpack29+0x60>
jmp    12b2 <Unpack29+0x142>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1030 <Unpack29_fileoutput@plt>
mov    0x2dd2(%rip),%rax
cmpq   $0x0,(%rax)
je     12a9 <Unpack29+0x139>
mov    -0x20(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122a <Unpack29+0xba>
jmp    12a4 <Unpack29+0x134>
mov    0x2db7(%rip),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jbe    1249 <Unpack29+0xd9>
jmp    12a4 <Unpack29+0x134>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
jne    126c <Unpack29+0xfc>
jmp    12a4 <Unpack29+0x134>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    0x2d48(%rip),%rax
mov    (%rax),%rax
mov    0x2d66(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2d56(%rip),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    120c <Unpack29+0x9c>
jmp    12a9 <Unpack29+0x139>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Unpack29>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2ece(%rip),%ecx
lea    0xe6b(%rip),%rdx
mov    %rsp,%rdi
mov    $0x63,%esi
call   1050 <snprintf@plt>
addl   $0x1,0x2eb3(%rip)
xor    %eax,%eax
call   1070 <tmpfile@plt>
test   %rax,%rax
je     1200 <Unpack29+0x90>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
call   1030 <Unpack29_fileoutput@plt>
mov    0x2ded(%rip),%r15
cmpq   $0x0,(%r15)
je     11f8 <Unpack29+0x88>
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     120d <Unpack29+0x9d>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %r14d,%r14
mov    0x2dd1(%rip),%rbp
mov    0x2dc2(%rip),%r12
xchg   %ax,%ax
mov    0x0(%rbp),%rax
cmp    %r14,(%rax)
ja     11f8 <Unpack29+0x88>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
je     11f8 <Unpack29+0x88>
mov    (%r15),%rcx
mov    0x0(%rbp),%rdx
mov    (%rdx),%rdx
mov    %al,(%rcx,%rdx,1)
mov    0x0(%rbp),%rax
addq   $0x1,(%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1220 <Unpack29+0xb0>
jmp    11f8 <Unpack29+0x88>

LLVM IR (-O0):
@Unpack29.i = internal global i32 0
@.str = [21 x i8] c"/tmp/unrar_tmpf_%06d\00"
@temp_output_buffer = external global i8*
@SEEK_SET = global i32 0
@temp_output_buffer_offset = external global i64*
@EOF = global i32 0
define void @Unpack29(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [100 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%13 = load i32, i32* @Unpack29.i
%14 = call i32 @snprintf(i8* %12, i32 99, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @Unpack29.i
%16 = add nsw i32 %15, 1
store i32 %16, i32* @Unpack29.i
%17 = call i32* (...) @tmpfile()
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %4
br label %67
21: ; preds = %4
%22 = load i32*, i32** %9
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @Unpack29_fileoutput(i32* %22, i32* %23, i32 %24, i32 %25, i32 %26)
%28 = load i8*, i8** @temp_output_buffer
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %64
30: ; preds = %21
%31 = load i32*, i32** %9
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
br label %34
34: ; preds = %53, %30
%35 = load i32*, i32** %9
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %63
39: ; preds = %34
%40 = load i64*, i64** @temp_output_buffer_offset
%41 = load i64, i64* %40
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = icmp ugt i64 %41, %43
br i1 %44, label %45, label %46
45: ; preds = %39
br label %63
46: ; preds = %39
%47 = load i32*, i32** %9
%48 = call i32 @fgetc(i32* %47)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %46
br label %63
53: ; preds = %46
%54 = load i32, i32* %10
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** @temp_output_buffer
%57 = load i64*, i64** @temp_output_buffer_offset
%58 = load i64, i64* %57
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
%60 = load i64*, i64** @temp_output_buffer_offset
%61 = load i64, i64* %60
%62 = add i64 %61, 1
store i64 %62, i64* %60
br label %34
63: ; preds = %52, %45, %34
br label %64
64: ; preds = %63, %21
%65 = load i32*, i32** %9
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %64, %20
ret void
}

LLVM IR (-O2):
@Unpack29.i = internal unnamed_addr global i32 0
@.str = [21 x i8] c"/tmp/unrar_tmpf_%06d\00"
@temp_output_buffer = external global i8*
@SEEK_SET = global i32 0
@temp_output_buffer_offset = external global i64*
@EOF = global i32 0
define void @Unpack29(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @Unpack29.i
%8 = call i32 @snprintf(i8* %6, i32 99, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @Unpack29.i
%10 = add nsw i32 %9, 1
store i32 %10, i32* @Unpack29.i
%11 = call i32* (...) @tmpfile()
%12 = icmp eq i32* %11, null
br i1 %12, label %45, label %13
13: ; preds = %4
%14 = call i32 @Unpack29_fileoutput(i32* %11, i32* %0, i32 %1, i32 %2, i32 %3)
%15 = load i8*, i8** @temp_output_buffer
%16 = icmp eq i8* %15, null
br i1 %16, label %43, label %17
17: ; preds = %13
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %11, i32 0, i32 %18)
%20 = call i32 @feof(i32* %11)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = sext i32 %1 to i64
br label %24
24: ; preds = %22, %32
%25 = load i64*, i64** @temp_output_buffer_offset
%26 = load i64, i64* %25
%27 = icmp ugt i64 %26, %23
br i1 %27, label %43, label %28
28: ; preds = %24
%29 = call i32 @fgetc(i32* %11)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %43, label %32
32: ; preds = %28
%33 = trunc i32 %29 to i8
%34 = load i8*, i8** @temp_output_buffer
%35 = load i64*, i64** @temp_output_buffer_offset
%36 = load i64, i64* %35
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
%38 = load i64*, i64** @temp_output_buffer_offset
%39 = load i64, i64* %38
%40 = add i64 %39, 1
store i64 %40, i64* %38
%41 = call i32 @feof(i32* %11)
%42 = icmp eq i32 %41, 0
br i1 %42, label %24, label %43
43: ; preds = %28, %24, %32, %17, %13
%44 = call i32 @fclose(i32* %11)
br label %45
45: ; preds = %4, %43
ret void
}