#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(unsigned char *, char *);
int /*<<< orphan*/ strcpy(unsigned char *, unsigned char *);
int strlen(unsigned char *);
int create_dns_file() {
  FILE *f;
  unsigned char buf[200];
  unsigned char *p;
  unsigned char *temp;
  int i, type, len;
  strcat(buf, "HEADER JUNK:");
  strcat(buf, "LL.MIT.EDU");
  i = len = strlen(buf);
  p = buf + i;
  *p++ = 0;
  *p++ = 16;
  *p++ = 0;
  *p++ = 1;
  p = buf + i + 4;
  len += 4;
  temp = "BLAH.MIT.EDU";
  strcpy(p, temp);
  i = strlen(temp);
  p += i;
  len += i;
  *p++ = 0;
  *p++ = 16;
  *p++ = 0;
  *p++ = 1;
  *p++ = 0;
  *p++ = 0;
  *p++ = 0;
  *p++ = 255;
  *p++ = 0;
  *p++ = 20;
  *p++ = 30;
  len += 11;
  strcat(p, "This is random junk in the TXT record that will overflow "
            "(*rr)->rr_u.rr_txt");
  f = fopen("dns-file", "w");
  p = buf;
  for (i = 0; i < len; i++, p++)
    fputc(*p, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<create_dns_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
lea    -0xd0(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1080 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <strcat@plt>
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xec(%rbp)
mov    %eax,-0xe4(%rbp)
lea    -0xd0(%rbp),%rax
movslq -0xe4(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x10,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x1,(%rax)
lea    -0xd0(%rbp),%rax
movslq -0xe4(%rbp),%rcx
add    %rcx,%rax
add    $0x4,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xec(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xec(%rbp)
lea    0xdc5(%rip),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xd8(%rbp),%rdi
mov    -0xe0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xe4(%rbp)
mov    -0xe4(%rbp),%ecx
mov    -0xd8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xe4(%rbp),%eax
add    -0xec(%rbp),%eax
mov    %eax,-0xec(%rbp)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x10,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x1,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0xff,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x14,(%rax)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x1e,(%rax)
mov    -0xec(%rbp),%eax
add    $0xb,%eax
mov    %eax,-0xec(%rbp)
mov    -0xd8(%rbp),%rdi
lea    0xc55(%rip),%rsi
call   1080 <strcat@plt>
lea    0xc95(%rip),%rdi
lea    0xc97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0xd0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    -0xe4(%rbp),%eax
cmp    -0xec(%rbp),%eax
jge    1451 <create_dns_file+0x2f1>
mov    -0xd8(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1060 <fputc@plt>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
mov    -0xd8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
jmp    1404 <create_dns_file+0x2a4>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dns_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc8,%rsp
lea    0xe8b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
movslq %eax,%r12
lea    (%rsp,%r12,1),%rbx
movl   $0x1001000,(%rsp,%r12,1)
01
lea    (%rsp,%r12,1),%rdi
add    $0x4,%rdi
lea    0xe60(%rip),%r15
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
cltq
movabs $0xff00000001001000,%rcx
mov    %rcx,0x4(%rax,%rbx,1)
movw   $0x1400,0xc(%rax,%rbx,1)
lea    0xf(%rax,%rbx,1),%rdi
movb   $0x1e,0xe(%rax,%rbx,1)
lea    (%r12,%rax,1),%ebx
add    $0xf,%ebx
lea    0xe2a(%rip),%rsi
call   1080 <strcat@plt>
lea    0xe6a(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    1245 <create_dns_file+0xe5>
add    %r15d,%r14d
add    $0xe,%r14d
add    $0x1,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%rsp,%rbx,1),%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1230 <create_dns_file+0xd0>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"HEADER JUNK:\00"
@.str.1 = [11 x i8] c"LL.MIT.EDU\00"
@.str.2 = [13 x i8] c"BLAH.MIT.EDU\00"
@.str.3 = [76 x i8] c"This is random junk in the TXT record that will overflow (*rr)->rr_u.rr_txt\00"
@.str.4 = [9 x i8] c"dns-file\00"
@.str.5 = [2 x i8] c"w\00"
define i32 @create_dns_file() {
%1 = alloca i32*
%2 = alloca [200 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%9 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
store i32 %13, i32* %5
%14 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
store i8 0, i8* %18
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
store i8 16, i8* %20
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 0, i8* %22
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 1, i8* %24
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 4
store i8* %30, i8** %3
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 4
store i32 %32, i32* %7
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %4
%33 = load i8*, i8** %3
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %4
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = load i8*, i8** %3
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %3
%42 = load i32, i32* %5
%43 = load i32, i32* %7
%44 = add nsw i32 %43, %42
store i32 %44, i32* %7
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %3
store i8 0, i8* %45
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %3
store i8 16, i8* %47
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
store i8 0, i8* %49
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
store i8 1, i8* %51
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %3
store i8 0, i8* %53
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %3
store i8 0, i8* %55
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %3
store i8 0, i8* %57
%59 = load i8*, i8** %3
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %3
store i8 -1, i8* %59
%61 = load i8*, i8** %3
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %3
store i8 0, i8* %61
%63 = load i8*, i8** %3
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %3
store i8 20, i8* %63
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %3
store i8 30, i8* %65
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 11
store i32 %68, i32* %7
%69 = load i8*, i8** %3
%70 = call i32 @strcat(i8* %69, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
%71 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %71, i32** %1
%72 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
store i8* %72, i8** %3
store i32 0, i32* %5
br label %73
73: ; preds = %82, %0
%74 = load i32, i32* %5
%75 = load i32, i32* %7
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %87
77: ; preds = %73
%78 = load i8*, i8** %3
%79 = load i8, i8* %78
%80 = load i32*, i32** %1
%81 = call i32 @fputc(i8 zeroext %79, i32* %80)
br label %82
82: ; preds = %77
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
%85 = load i8*, i8** %3
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %3
br label %73
87: ; preds = %73
%88 = load i32*, i32** %1
%89 = call i32 @fclose(i32* %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"HEADER JUNK:\00"
@.str.1 = [11 x i8] c"LL.MIT.EDU\00"
@.str.2 = [13 x i8] c"BLAH.MIT.EDU\00"
@.str.3 = [76 x i8] c"This is random junk in the TXT record that will overflow (*rr)->rr_u.rr_txt\00"
@.str.4 = [9 x i8] c"dns-file\00"
@.str.5 = [2 x i8] c"w\00"
define i32 @create_dns_file() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @strlen(i8* %2)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %7
%9 = getelementptr inbounds i8, i8* %7, i64 2
store i8 16, i8* %8
%10 = getelementptr inbounds i8, i8* %7, i64 3
store i8 0, i8* %9
store i8 1, i8* %10
%11 = getelementptr inbounds i8, i8* %7, i64 4
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 16, i8* %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 1, i8* %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 0, i8* %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8 0, i8* %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 -1, i8* %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8 0, i8* %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 20, i8* %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 30, i8* %25
%27 = add i32 %5, 15
%28 = add i32 %27, %13
%29 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp sgt i32 %28, 0
br i1 %31, label %32, label %43
32: ; preds = %0
%33 = add i32 %5, %13
%34 = add i32 %33, 14
%35 = zext i32 %34 to i64
%36 = getelementptr [200 x i8], [200 x i8]* %1, i64 0, i64 %35
br label %37
37: ; preds = %32, %37
%38 = phi i8* [ %41, %37 ], [ %2, %32 ]
%39 = load i8, i8* %38
%40 = call i32 @fputc(i8 zeroext %39, i32* %30)
%41 = getelementptr inbounds i8, i8* %38, i64 1
%42 = icmp eq i8* %38, %36
br i1 %42, label %43, label %37
43: ; preds = %37, %0
%44 = call i32 @fclose(i32* %30)
ret i32 0
}