#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 */
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *, ...);
char *strstr(char *, char *);
int main(void) {
  int x, y, i, j, cnt;
  char *query, *cookies, tmp[1000];
  query = getenv("QUERY_STRING");
  if (sscanf(query, "x=%d&y=%d", &x, &y) != 2)
    x = y = 1;
  cookies = getenv("HTTP_COOKIE");
  if (cookies == NULL)
    cnt = 0;
  else {
    char *s = strstr(cookies, "cnt=");
    if (s == NULL)
      cnt = 0;
    else
      sscanf(s, "cnt=%d%s", &cnt, tmp);
  }
  if (x < 0)
    x *= -1;
  if (y < 0)
    y *= -1;
  printf("Set-Cookie: cnt=%d; host=mail.ru.;\n", ++cnt);
  printf("Content-Type: text/html;\n\n");
  printf("<html><head><title>Test</title><meta charset='utf-8' /></head><body>"
         "<form><label for='x'>X:</label> <input type='text' name='x' "
         "value='%d' /> "
         "<label for='x'>Y:</label> <input type='text' name='y' value='%d' /> "
         "<input type='submit' value='Считать' /></form><table>",
         x, y);
  for (j = 1; j <= y; j++) {
    printf("<tr>");
    for (i = 1; i <= x; i++)
      printf("<td>%d</td>", i * j);
    printf("</tr>");
  }
  printf("</table>%s</body></html>", cookies);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xea0(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x2,%eax
je     1193 <main+0x53>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ba <main+0x7a>
movl   $0x0,-0x18(%rbp)
jmp    1210 <main+0xd0>
mov    -0x28(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11eb <main+0xab>
movl   $0x0,-0x18(%rbp)
jmp    120b <main+0xcb>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rcx
lea    0xe28(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
jmp    1210 <main+0xd0>
cmpl   $0x0,-0x8(%rbp)
jge    1221 <main+0xe1>
imul   $0xffffffff,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1232 <main+0xf2>
imul   $0xffffffff,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12de <main+0x19e>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12c2 <main+0x182>
mov    -0x10(%rbp),%esi
imul   -0x14(%rbp),%esi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1293 <main+0x153>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1272 <main+0x132>
mov    -0x28(%rbp),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe98(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe99(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     119d <main+0x4d>
movl   $0x1,0xc(%rsp)
movl   $0x1,0x10(%rsp)
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
mov    %rax,0x18(%rsp)
je     11e4 <main+0x94>
lea    0xe69(%rip),%rsi
mov    %rax,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11e4 <main+0x94>
lea    0xe5a(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
jmp    11ec <main+0x9c>
movl   $0x0,0x14(%rsp)
mov    0x10(%rsp),%eax
test   %eax,%eax
jns    11fa <main+0xaa>
neg    %eax
mov    %eax,0x10(%rsp)
mov    0xc(%rsp),%eax
test   %eax,%eax
jns    1208 <main+0xb8>
neg    %eax
mov    %eax,0xc(%rsp)
mov    0x14(%rsp),%esi
add    $0x1,%esi
mov    %esi,0x14(%rsp)
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf6c(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    12bb <main+0x16b>
mov    $0x1,%ebx
lea    0xf0e(%rip),%r15
lea    0xf18(%rip),%r12
lea    0xf05(%rip),%r13
jmp    1285 <main+0x135>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
jge    12bb <main+0x16b>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x10(%rsp)
jle    1270 <main+0x120>
xor    %r14d,%r14d
mov    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14d
add    %ebx,%ebp
cmp    0x10(%rsp),%r14d
jl     12a0 <main+0x150>
jmp    1270 <main+0x120>
lea    0xeb9(%rip),%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [10 x i8] c"x=%d&y=%d\00"
@.str.2 = [12 x i8] c"HTTP_COOKIE\00"
@.str.3 = [5 x i8] c"cnt=\00"
@.str.4 = [9 x i8] c"cnt=%d%s\00"
@.str.5 = [36 x i8] c"Set-Cookie: cnt=%d; host=mail.ru.;\0A\00"
@.str.6 = [27 x i8] c"Content-Type: text/html;\0A\0A\00"
@.str.7 = [271 x i8] c"<html><head><title>Test</title><meta charset='utf-8' /></head><body><form><label for='x'>X:</label> <input type='text' name='x' value='%d' /> <label for='x'>Y:</label> <input type='text' name='y' value='%d' /> <input type='submit' value='\D0\A1\D1\87\D0\B8\D1\82\D0\B0\D1\82\D1\8C' /></form><table>\00"
@.str.8 = [5 x i8] c"<tr>\00"
@.str.9 = [12 x i8] c"<td>%d</td>\00"
@.str.10 = [6 x i8] c"</tr>\00"
@.str.11 = [25 x i8] c"</table>%s</body></html>\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [1000 x i8]
%10 = alloca i8*
store i32 0, i32* %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 1, i32* %3
store i32 1, i32* %2
br label %16
16: ; preds = %15, %0
%17 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %6
br label %32
21: ; preds = %16
%22 = load i8*, i8** %8
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %6
br label %31
27: ; preds = %21
%28 = load i8*, i8** %10
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%30 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %6, i8* %29)
br label %31
31: ; preds = %27, %26
br label %32
32: ; preds = %31, %20
%33 = load i32, i32* %2
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %2
%37 = mul nsw i32 %36, -1
store i32 %37, i32* %2
br label %38
38: ; preds = %35, %32
%39 = load i32, i32* %3
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %3
%43 = mul nsw i32 %42, -1
store i32 %43, i32* %3
br label %44
44: ; preds = %41, %38
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%49 = load i32, i32* %2
%50 = load i32, i32* %3
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([271 x i8], [271 x i8]* @.str.7, i64 0, i64 0), i32 %49, i32 %50)
store i32 1, i32* %5
br label %52
52: ; preds = %72, %44
%53 = load i32, i32* %5
%54 = load i32, i32* %3
%55 = icmp sle i32 %53, %54
br i1 %55, label %56, label %75
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %4
br label %58
58: ; preds = %67, %56
%59 = load i32, i32* %4
%60 = load i32, i32* %2
%61 = icmp sle i32 %59, %60
br i1 %61, label %62, label %70
62: ; preds = %58
%63 = load i32, i32* %4
%64 = load i32, i32* %5
%65 = mul nsw i32 %63, %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %62
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
store i32 %69, i32* %4
br label %58
70: ; preds = %58
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %72
72: ; preds = %70
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
store i32 %74, i32* %5
br label %52
75: ; preds = %52
%76 = load i8*, i8** %8
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %76)
ret i32 1
}

LLVM IR (-O2):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [10 x i8] c"x=%d&y=%d\00"
@.str.2 = [12 x i8] c"HTTP_COOKIE\00"
@.str.3 = [5 x i8] c"cnt=\00"
@.str.4 = [9 x i8] c"cnt=%d%s\00"
@.str.5 = [36 x i8] c"Set-Cookie: cnt=%d; host=mail.ru.;\0A\00"
@.str.7 = [271 x i8] c"<html><head><title>Test</title><meta charset='utf-8' /></head><body><form><label for='x'>X:</label> <input type='text' name='x' value='%d' /> <label for='x'>Y:</label> <input type='text' name='y' value='%d' /> <input type='submit' value='\D0\A1\D1\87\D0\B8\D1\82\D0\B0\D1\82\D1\8C' /></form><table>\00"
@.str.8 = [5 x i8] c"<tr>\00"
@.str.9 = [12 x i8] c"<td>%d</td>\00"
@.str.10 = [6 x i8] c"</tr>\00"
@.str.11 = [25 x i8] c"</table>%s</body></html>\00"
@str = [26 x i8] c"Content-Type: text/html;\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%11 = icmp eq i32 %10, 2
br i1 %11, label %13, label %12
12: ; preds = %0
store i32 1, i32* %2
store i32 1, i32* %1
br label %13
13: ; preds = %12, %0
%14 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %3
br label %23
17: ; preds = %13
%18 = call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %3
br label %23
21: ; preds = %17
%22 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* %3, i8* %8)
br label %23
23: ; preds = %20, %21, %16
%24 = load i32, i32* %1
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = sub nsw i32 0, %24
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %2
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = sub nsw i32 0, %29
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%38 = load i32, i32* %1
%39 = load i32, i32* %2
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([271 x i8], [271 x i8]* @.str.7, i64 0, i64 0), i32 %38, i32 %39)
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 1
br i1 %42, label %60, label %43
43: ; preds = %33, %55
%44 = phi i32 [ %57, %55 ], [ 1, %33 ]
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%46 = load i32, i32* %1
%47 = icmp slt i32 %46, 1
br i1 %47, label %55, label %48
48: ; preds = %43, %48
%49 = phi i32 [ %52, %48 ], [ 1, %43 ]
%50 = mul nuw nsw i32 %49, %44
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %50)
%52 = add nuw nsw i32 %49, 1
%53 = load i32, i32* %1
%54 = icmp slt i32 %49, %53
br i1 %54, label %48, label %55
55: ; preds = %48, %43
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%57 = add nuw nsw i32 %44, 1
%58 = load i32, i32* %2
%59 = icmp slt i32 %44, %58
br i1 %59, label %43, label %60
60: ; preds = %55, %33
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %14)
ret i32 1
}