#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(int);
int maxEnvelopes(int **, int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3 || argc % 2 == 0) {
    fprintf(stderr, "Usage: ./test w0 h0 w1 h1...");
    exit(-1);
  }
  int i, size = (argc - 1) / 2;
  int *col_sizes = malloc(size * sizeof(int));
  int **envelopes = malloc(size * sizeof(int *));
  for (i = 0; i < size; i++) {
    col_sizes[i] = 2;
    envelopes[i] = malloc(col_sizes[i] * sizeof(int));
    envelopes[i][0] = atoi(argv[i * 2 + 1]);
    envelopes[i][1] = atoi(argv[i * 2 + 2]);
  }
  printf("%d\n", maxEnvelopes(envelopes, size, col_sizes));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1194 <main+0x34>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b3 <main+0x53>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1293 <main+0x133>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x2,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movslq (%rax,%rcx,4),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rdx
mov    (%rax,%rdx,8),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <main+0x91>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1080 <maxEnvelopes@plt>
mov    %eax,%esi
lea    0xd71(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jl     1229 <main+0xc9>
mov    %edi,%ebx
mov    %edi,%eax
and    $0x1,%eax
je     1229 <main+0xc9>
mov    %rsi,%r13
add    $0xffffffff,%ebx
shr    %ebx
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0x0(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rbx,(%rsp)
lea    0x0(,%rbx,4),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
movl   $0x2,(%r15,%r14,1)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r12,%r14,2)
mov    0x8(%r13,%r14,4),%rdi
call   1060 <atoi@plt>
mov    %eax,(%rbx)
mov    0x10(%r13,%r14,4),%rdi
call   1060 <atoi@plt>
mov    %eax,0x4(%rbx)
add    $0x4,%r14
cmp    %r14,%rbp
jne    11c0 <main+0x60>
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
call   1080 <maxEnvelopes@plt>
lea    0xe0c(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./test w0 h0 w1 h1...\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12, %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = sdiv i32 %22, 2
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
%29 = bitcast i8* %28 to i32*
store i32* %29, i32** %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
%35 = bitcast i8* %34 to i32**
store i32** %35, i32*** %9
store i32 0, i32* %6
br label %36
36: ; preds = %87, %20
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %90
40: ; preds = %36
%41 = load i32*, i32** %8
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 2, i32* %44
%45 = load i32*, i32** %8
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 4
%52 = trunc i64 %51 to i32
%53 = call i8* @malloc(i32 %52)
%54 = bitcast i8* %53 to i32*
%55 = load i32**, i32*** %9
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32*, i32** %55, i64 %57
store i32* %54, i32** %58
%59 = load i8**, i8*** %5
%60 = load i32, i32* %6
%61 = mul nsw i32 %60, 2
%62 = add nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %59, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
%67 = load i32**, i32*** %9
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32*, i32** %67, i64 %69
%71 = load i32*, i32** %70
%72 = getelementptr inbounds i32, i32* %71, i64 0
store i32 %66, i32* %72
%73 = load i8**, i8*** %5
%74 = load i32, i32* %6
%75 = mul nsw i32 %74, 2
%76 = add nsw i32 %75, 2
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %73, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @atoi(i8* %79)
%81 = load i32**, i32*** %9
%82 = load i32, i32* %6
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32*, i32** %81, i64 %83
%85 = load i32*, i32** %84
%86 = getelementptr inbounds i32, i32* %85, i64 1
store i32 %80, i32* %86
br label %87
87: ; preds = %40
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
store i32 %89, i32* %6
br label %36
90: ; preds = %36
%91 = load i32**, i32*** %9
%92 = load i32, i32* %7
%93 = load i32*, i32** %8
%94 = call i32 @maxEnvelopes(i32** %91, i32 %92, i32* %93)
%95 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %94)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: ./test w0 h0 w1 h1...\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
%4 = and i32 %0, 1
%5 = icmp eq i32 %4, 0
%6 = or i1 %3, %5
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = add nsw i32 %0, -1
%13 = lshr i32 %12, 1
%14 = shl nuw i32 %13, 2
%15 = tail call i8* @malloc(i32 %14)
%16 = bitcast i8* %15 to i32*
%17 = shl i32 %13, 3
%18 = tail call i8* @malloc(i32 %17)
%19 = bitcast i8* %18 to i32**
%20 = zext i32 %13 to i64
br label %21
21: ; preds = %11, %21
%22 = phi i64 [ 0, %11 ], [ %38, %21 ]
%23 = getelementptr inbounds i32, i32* %16, i64 %22
store i32 2, i32* %23
%24 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%25 = bitcast i8* %24 to i32*
%26 = getelementptr inbounds i32*, i32** %19, i64 %22
%27 = bitcast i32** %26 to i8**
store i8* %24, i8** %27
%28 = shl nuw nsw i64 %22, 1
%29 = or i64 %28, 1
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @atoi(i8* %31)
store i32 %32, i32* %25
%33 = add nuw nsw i64 %28, 2
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = tail call i32 @atoi(i8* %35)
%37 = getelementptr inbounds i32, i32* %25, i64 1
store i32 %36, i32* %37
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, %20
br i1 %39, label %40, label %21
40: ; preds = %21
%41 = tail call i32 @maxEnvelopes(i32** %19, i32 %13, i32* %16)
%42 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
ret i32 0
}