#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 */

/* Variables and functions */
int EOF;
int atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ find_lzma_header(unsigned char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  unsigned char buf[4096];
  int ret, i, numlzma, blocks = 0;
  if (argc != 2) {
    printf(
        "usage: %s numlzma < infile | lzma -c -d > outfile\n"
        "where numlzma is index of lzma file to extract, starting from zero.\n",
        argv[0]);
    exit(1);
  }
  numlzma = atoi(argv[1]);
  for (;;) {
    ret = fread(buf, 4096, 1, stdin);
    if (ret != 1)
      break;
    for (i = 0; i < 4096 - 23; i++) {
      if (find_lzma_header(buf + i) && numlzma-- <= 0) {
        fwrite(buf + i, (4096 - i), 1, stdout);
        for (;;) {
          int ch;
          ch = getchar();
          if (ch == EOF)
            exit(0);
          putchar(ch);
        }
      }
    }
    blocks++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1020(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ca <main+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x101c(%rbp)
lea    -0x1010(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x1014(%rbp)
cmpl   $0x1,-0x1014(%rbp)
je     1214 <main+0x94>
jmp    12fd <main+0x17d>
movl   $0x0,-0x1018(%rbp)
cmpl   $0xfe9,-0x1018(%rbp)
jge    12e9 <main+0x169>
lea    -0x1010(%rbp),%rdi
movslq -0x1018(%rbp),%rax
add    %rax,%rdi
call   1060 <find_lzma_header@plt>
cmp    $0x0,%rax
je     12d0 <main+0x150>
mov    -0x101c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x101c(%rbp)
cmp    $0x0,%eax
jg     12d0 <main+0x150>
lea    -0x1010(%rbp),%rdi
movslq -0x1018(%rbp),%rax
add    %rax,%rdi
mov    $0x1000,%esi
sub    -0x1018(%rbp),%esi
mov    0x2d45(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%eax
mov    0x2d2f(%rip),%rcx
cmp    (%rcx),%eax
jne    12c0 <main+0x140>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x1024(%rbp),%edi
call   1030 <putchar@plt>
jmp    1297 <main+0x117>
jmp    12d5 <main+0x155>
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
jmp    121e <main+0x9e>
mov    -0x1020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1020(%rbp)
jmp    11dd <main+0x5d>
mov    $0x1,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
cmp    $0x2,%edi
jne    1279 <main+0xf9>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x2e3d(%rip),%r15
mov    (%r15),%ecx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1216 <main+0x96>
xor    %ebp,%ebp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
lea    (%rsp,%rbp,1),%rbx
mov    %rbx,%rdi
call   1060 <find_lzma_header@plt>
test   %rax,%rax
je     11ea <main+0x6a>
test   %r12d,%r12d
jle    122b <main+0xab>
add    $0xffffffff,%r12d
add    $0x1,%rbp
cmp    $0xfe9,%rbp
jne    11d0 <main+0x50>
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    $0x0,%ebp
cmp    $0x1,%eax
je     11d0 <main+0x50>
mov    $0x1,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1000,%esi
sub    %ebp,%esi
mov    0x2d97(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2d8a(%rip),%rbx
cmp    (%rbx),%eax
je     1272 <main+0xf2>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%rbx),%eax
jne    1260 <main+0xe0>
xor    %edi,%edi
call   1090 <exit@plt>
mov    (%rsi),%rsi
lea    0xd7d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [119 x i8] c"usage: %s numlzma < infile | lzma -c -d > outfile\0Awhere numlzma is index of lzma file to extract, starting from zero.\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %9
br label %25
25: ; preds = %70, %20
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i32 @fread(i8* %26, i32 4096, i32 1, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %25
br label %73
32: ; preds = %25
store i32 0, i32* %8
br label %33
33: ; preds = %67, %32
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 4073
br i1 %35, label %36, label %70
36: ; preds = %33
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i64 @find_lzma_header(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %66
43: ; preds = %36
%44 = load i32, i32* %9
%45 = add nsw i32 %44, -1
store i32 %45, i32* %9
%46 = icmp sle i32 %44, 0
br i1 %46, label %47, label %66
47: ; preds = %43
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i32, i32* %8
%53 = sub nsw i32 4096, %52
%54 = load i32, i32* @stdout
%55 = call i32 @fwrite(i8* %51, i32 %53, i32 1, i32 %54)
br label %56
56: ; preds = %63, %47
%57 = call i32 (...) @getchar()
store i32 %57, i32* %11
%58 = load i32, i32* %11
%59 = load i32, i32* @EOF
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %56
%64 = load i32, i32* %11
%65 = call i32 @putchar(i32 %64)
br label %56
66: ; preds = %43, %36
br label %67
67: ; preds = %66
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %33
70: ; preds = %33
%71 = load i32, i32* %10
%72 = add nsw i32 %71, 1
store i32 %72, i32* %10
br label %25
73: ; preds = %31
ret i32 1
}

LLVM IR (-O2):
@.str = [119 x i8] c"usage: %s numlzma < infile | lzma -c -d > outfile\0Awhere numlzma is index of lzma file to extract, starting from zero.\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = load i32, i32* @stdin
%15 = call i32 @fread(i8* %4, i32 4096, i32 1, i32 %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %21, label %52
17: ; preds = %46
%18 = load i32, i32* @stdin
%19 = call i32 @fread(i8* %4, i32 4096, i32 1, i32 %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %50, label %52
21: ; preds = %10, %50
%22 = phi i64 [ %51, %50 ], [ 0, %10 ]
%23 = phi i32 [ %47, %50 ], [ %13, %10 ]
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %22
%25 = call i64 @find_lzma_header(i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %46, label %27
27: ; preds = %21
%28 = add nsw i32 %23, -1
%29 = icmp slt i32 %23, 1
br i1 %29, label %30, label %46
30: ; preds = %27
%31 = trunc i64 %22 to i32
%32 = sub nuw nsw i32 4096, %31
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i8* %24, i32 %32, i32 1, i32 %33)
%35 = call i32 (...) @getchar()
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %40, %30
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %30, %40
%41 = phi i32 [ %43, %40 ], [ %35, %30 ]
%42 = call i32 @putchar(i32 %41)
%43 = call i32 (...) @getchar()
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %38, label %40
46: ; preds = %21, %27
%47 = phi i32 [ %28, %27 ], [ %23, %21 ]
%48 = add nuw nsw i64 %22, 1
%49 = icmp eq i64 %48, 4073
br i1 %49, label %17, label %50
50: ; preds = %46, %17
%51 = phi i64 [ %48, %46 ], [ 0, %17 ]
br label %21
52: ; preds = %17, %10
ret i32 1
}