#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 PrintError(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int main3(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int strlen(char *);
int main2(int numArgs, const char *args[], char *rs) {
  FILE *inFile = 0;
  FILE *outFile = 0;
  int res;
  sprintf(
      rs + strlen(rs),
      "\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\n");
  if (numArgs < 2 || numArgs > 3) {
    sprintf(rs + strlen(rs), "\nUsage:  lzmadec file.lzma [outFile]\n");
    return 1;
  }
  inFile = fopen(args[1], "rb");
  if (inFile == 0)
    return PrintError(rs, "Can not open input file");
  if (numArgs > 2) {
    outFile = fopen(args[2], "wb+");
    if (outFile == 0)
      return PrintError(rs, "Can not open output file");
  }
  res = main3(inFile, outFile, rs);
  if (outFile != 0)
    fclose(outFile);
  fclose(inFile);
  return res;
}


x86 assembly (clang, -O0):
<main2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe5c(%rip),%rsi
call   1080 <sprintf@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11bd <main2+0x5d>
cmpl   $0x3,-0x8(%rbp)
jle    11ef <main2+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe66(%rip),%rsi
call   1080 <sprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <main2+0x14b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122a <main2+0xca>
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1070 <PrintError@plt>
mov    %eax,-0x4(%rbp)
jmp    12ab <main2+0x14b>
cmpl   $0x2,-0x8(%rbp)
jle    1274 <main2+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126f <main2+0x10f>
mov    -0x18(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1070 <PrintError@plt>
mov    %eax,-0x4(%rbp)
jmp    12ab <main2+0x14b>
jmp    1274 <main2+0x114>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <main3@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     129c <main2+0x13c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rdx,%rdi
call   1040 <strlen@plt>
cltq
movups 0xe8e(%rip),%xmm0
movups %xmm0,(%rbx,%rax,1)
movups 0xe93(%rip),%xmm0
movups %xmm0,0x10(%rbx,%rax,1)
movups 0xe97(%rip),%xmm0
movups %xmm0,0x20(%rbx,%rax,1)
movups 0xe9b(%rip),%xmm0
movups %xmm0,0x30(%rbx,%rax,1)
movl   $0xa3530,0x40(%rbx,%rax,1)
lea    -0x4(%r12),%eax
cmp    $0xfffffffd,%eax
ja     11e3 <main2+0x93>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movups 0xe87(%rip),%xmm0
movups %xmm0,(%rbx,%rax,1)
movups 0xe8c(%rip),%xmm0
movups %xmm0,0x10(%rbx,%rax,1)
movabs $0xa5d656c694674,%rcx
mov    %rcx,0x1e(%rbx,%rax,1)
mov    $0x1,%ebx
jmp    1253 <main2+0x103>
mov    0x8(%r15),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1233 <main2+0xe3>
mov    %rax,%r14
cmp    $0x2,%r12d
jbe    123c <main2+0xec>
mov    0x10(%r15),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1261 <main2+0x111>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1050 <main3@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    124b <main2+0xfb>
lea    0xe33(%rip),%rsi
jmp    1268 <main2+0x118>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <main3@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <PrintError@plt>

LLVM IR (-O0):
@.str = [68 x i8] c"\0ALZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-05\0A\00"
@.str.1 = [38 x i8] c"\0AUsage: lzmadec file.lzma [outFile]\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"Can not open input file\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.5 = [25 x i8] c"Can not open output file\00"
define i32 @main2(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32* null, i32** %8
store i32* null, i32** %9
%11 = load i8*, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 2
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 3
br i1 %21, label %22, label %29
22: ; preds = %19, %3
%23 = load i8*, i8** %7
%24 = load i8*, i8** %7
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %67
29: ; preds = %19
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i8*, i8** %7
%38 = call i32 @PrintError(i8* %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 %38, i32* %4
br label %67
39: ; preds = %29
%40 = load i32, i32* %5
%41 = icmp sgt i32 %40, 2
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %9
%47 = load i32*, i32** %9
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = load i8*, i8** %7
%51 = call i32 @PrintError(i8* %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
store i32 %51, i32* %4
br label %67
52: ; preds = %42
br label %53
53: ; preds = %52, %39
%54 = load i32*, i32** %8
%55 = load i32*, i32** %9
%56 = load i8*, i8** %7
%57 = call i32 @main3(i32* %54, i32* %55, i8* %56)
store i32 %57, i32* %10
%58 = load i32*, i32** %9
%59 = icmp ne i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = load i32*, i32** %9
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %60, %53
%64 = load i32*, i32** %8
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* %10
store i32 %66, i32* %4
br label %67
67: ; preds = %63, %49, %36, %22
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@.str = [68 x i8] c"\0ALZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-05\0A\00"
@.str.1 = [38 x i8] c"\0AUsage: lzmadec file.lzma [outFile]\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [24 x i8] c"Can not open input file\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.5 = [25 x i8] c"Can not open output file\00"
define i32 @main2(i32 %0, i8** nocapture %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %2, i64 %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(68) %6, i8* align 1 dereferenceable(68) getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i64 68, i1 false)
%7 = add i32 %0, -4
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %2)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %2, i64 %11
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(38) %12, i8* align 1 dereferenceable(38) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 38, i1 false)
br label %37
13: ; preds = %3
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @PrintError(i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %37
20: ; preds = %13
%21 = icmp ugt i32 %0, 2
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = tail call i32 @main3(i32* %16, i32* null, i8* %2)
br label %34
24: ; preds = %20
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @PrintError(i8* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %37
31: ; preds = %24
%32 = tail call i32 @main3(i32* %16, i32* %27, i8* %2)
%33 = tail call i32 @fclose(i32* %27)
br label %34
34: ; preds = %22, %31
%35 = phi i32 [ %23, %22 ], [ %32, %31 ]
%36 = tail call i32 @fclose(i32* %16)
br label %37
37: ; preds = %34, %29, %18, %9
%38 = phi i32 [ 1, %9 ], [ %19, %18 ], [ %30, %29 ], [ %35, %34 ]
ret i32 %38
}