#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 /*<<< orphan*/ fgets(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, long *);
int /*<<< orphan*/ stdin;
int main(void) {
  char *lenstr;
  char input[80];
  long len;
  FILE *fout;
  int error;
  printf("Content-Type:text/html\n\n");
  printf("<html>\n<head>\n");
  printf("<title>Ejercicio 2: Formulario CGI y Leng. C</title>\n");
  printf("</head>\n<body>\n");
  lenstr = getenv("CONTENT_LENGTH");
  if (lenstr == NULL || sscanf(lenstr, "%ld", &len) != 1 || len > 80) {
  } else {
    if ((fout = fopen("/home/afast/web/datos_alumno.txt", "w")) == NULL) {
      error = 1;
    } else {
      fgets(input, len + 1, stdin);
      error = 0;
    }
  }
  printf("</body>\n");
  printf("</html>\n");
  return error;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d5 <main+0x85>
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
lea    -0x68(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11d5 <main+0x85>
cmpq   $0x50,-0x68(%rbp)
jle    11da <main+0x8a>
jmp    122d <main+0xdd>
lea    0xea0(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    1207 <main+0xb7>
movl   $0x1,-0x74(%rbp)
jmp    1228 <main+0xd8>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
add    $0x1,%rsi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
movl   $0x0,-0x74(%rbp)
jmp    122d <main+0xdd>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
lea    0xee6(%rip),%rdi
call   1040 <puts@plt>
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf11(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ef <main+0x9f>
lea    0xe72(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11f6 <main+0xa6>
cmpq   $0x50,0x8(%rsp)
jg     11f6 <main+0xa6>
lea    0xe55(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
mov    0x8(%rsp),%rsi
add    $0x1,%rsi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
call   1050 <fgets@plt>
xor    %ebx,%ebx
jmp    11f6 <main+0xa6>
jmp    11f6 <main+0xa6>
mov    $0x1,%ebx
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Content-Type:text/html\0A\0A\00"
@.str.1 = [15 x i8] c"<html>\0A<head>\0A\00"
@.str.2 = [54 x i8] c"<title>Ejercicio 2: Formulario CGI y Leng. C</title>\0A\00"
@.str.3 = [16 x i8] c"</head>\0A<body>\0A\00"
@.str.4 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.5 = [4 x i8] c"%ld\00"
@.str.6 = [33 x i8] c"/home/afast/web/datos_alumno.txt\00"
@.str.7 = [2 x i8] c"w\00"
@stdin = global i32 0
@.str.8 = [9 x i8] c"</body>\0A\00"
@.str.9 = [9 x i8] c"</html>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%11 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %0
%15 = load i8*, i8** %2
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64* %4)
%17 = icmp ne i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i64, i64* %4
%20 = icmp sgt i64 %19, 80
br i1 %20, label %21, label %22
21: ; preds = %18, %14, %0
br label %33
22: ; preds = %18
%23 = call i32* @fopen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %23, i32** %5
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %6
br label %32
26: ; preds = %22
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%28 = load i64, i64* %4
%29 = add nsw i64 %28, 1
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %27, i64 %29, i32 %30)
store i32 0, i32* %6
br label %32
32: ; preds = %26, %25
br label %33
33: ; preds = %32, %21
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@.str.4 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.5 = [4 x i8] c"%ld\00"
@.str.6 = [33 x i8] c"/home/afast/web/datos_alumno.txt\00"
@.str.7 = [2 x i8] c"w\00"
@stdin = global i32 0
@str = [24 x i8] c"Content-Type:text/html\0A\00"
@str.10 = [14 x i8] c"<html>\0A<head>\00"
@str.11 = [53 x i8] c"<title>Ejercicio 2: Formulario CGI y Leng. C</title>\00"
@str.12 = [15 x i8] c"</head>\0A<body>\00"
@str.13 = [8 x i8] c"</body>\00"
@str.14 = [8 x i8] c"</html>\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %25, label %11
11: ; preds = %0
%12 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64* %2)
%13 = icmp ne i32 %12, 1
%14 = load i64, i64* %2
%15 = icmp sgt i64 %14, 80
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %25, label %17
17: ; preds = %11
%18 = call i32* @fopen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = load i64, i64* %2
%22 = add nsw i64 %21, 1
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %3, i64 %22, i32 %23)
br label %25
25: ; preds = %17, %20, %0, %11
%26 = phi i32 [ undef, %0 ], [ undef, %11 ], [ 0, %20 ], [ 1, %17 ]
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.13, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.14, i64 0, i64 0))
ret i32 %26
}