#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, int, int, int, int, int, int, char *,
                           int, int, int, int, int, int, int, int);
int open(char *, int, int);
int main() {
  char *str =
      "#include <unistd.h>%c#include <fcntl.h>%c#include <stdio.h>%c#define "
      "STRINGIFY2( x) #x%c#define STRINGIFY(x) STRINGIFY2(x)%c#define GRACE "
      "int main(){char *str=%c%s%c;int fd=open(%cGrace_kid.c%c, "
      "O_CREAT|O_TRUNC|O_RDWR, 0644);dprintf(fd, str, 10, 10, 10, 10, 10, 34, "
      "str, 34, 34, 34, 10, 10, 10, 10, 10);close(fd);return 0;}%cGRACE%c/*%c  "
      " Comment out of functions%c*/%c";
  int fd = open("Grace_kid.c", O_CREAT | O_TRUNC | O_RDWR, 0644);
  dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 34, 34, 10, 10, 10, 10, 10);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
mov    0x2e96(%rip),%rax
or     (%rax),%esi
mov    0x2e75(%rip),%rax
or     (%rax),%esi
lea    0x1006(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    $0xa,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0xa,(%rsp)
movl   $0x22,0x8(%rsp)
mov    %rax,0x10(%rsp)
movl   $0x22,0x18(%rsp)
movl   $0x22,0x20(%rsp)
movl   $0x22,0x28(%rsp)
movl   $0xa,0x30(%rsp)
movl   $0xa,0x38(%rsp)
movl   $0xa,0x40(%rsp)
movl   $0xa,0x48(%rsp)
movl   $0xa,0x50(%rsp)
call   1040 <dprintf@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ec0(%rip),%rax
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8e(%rip),%rax
or     (%rax),%esi
lea    0x101f(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,%ebx
sub    $0x8,%rsp
lea    0xe96(%rip),%rsi
mov    %eax,%edi
mov    $0xa,%edx
mov    $0xa,%ecx
mov    $0xa,%r8d
mov    $0xa,%r9d
push   $0xa
push   $0xa
push   $0xa
push   $0xa
push   $0xa
push   $0x22
push   $0x22
push   $0x22
push   %rsi
push   $0x22
push   $0xa
call   1040 <dprintf@plt>
add    $0x60,%rsp
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [370 x i8] c"#include <unistd.h>%c#include <fcntl.h>%c#include <stdio.h>%c#define STRINGIFY2( x) #x%c#define STRINGIFY(x) STRINGIFY2(x)%c#define GRACE int main(){char *str=%c%s%c;int fd=open(%cGrace_kid.c%c, O_CREAT|O_TRUNC|O_RDWR, 0644);dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 34, 34, 10, 10, 10, 10, 10);close(fd);return 0;}%cGRACE%c/*%c Comment out of functions%c*/%c\00"
@.str.1 = [12 x i8] c"Grace_kid.c\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([370 x i8], [370 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @O_RDWR
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 420)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @dprintf(i32 %10, i8* %11, i32 10, i32 10, i32 10, i32 10, i32 10, i32 34, i8* %12, i32 34, i32 34, i32 34, i32 10, i32 10, i32 10, i32 10, i32 10)
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [370 x i8] c"#include <unistd.h>%c#include <fcntl.h>%c#include <stdio.h>%c#define STRINGIFY2( x) #x%c#define STRINGIFY(x) STRINGIFY2(x)%c#define GRACE int main(){char *str=%c%s%c;int fd=open(%cGrace_kid.c%c, O_CREAT|O_TRUNC|O_RDWR, 0644);dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 34, 34, 10, 10, 10, 10, 10);close(fd);return 0;}%cGRACE%c/*%c Comment out of functions%c*/%c\00"
@.str.1 = [12 x i8] c"Grace_kid.c\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_TRUNC
%3 = or i32 %2, %1
%4 = load i32, i32* @O_RDWR
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 420)
%7 = tail call i32 @dprintf(i32 %6, i8* getelementptr inbounds ([370 x i8], [370 x i8]* @.str, i64 0, i64 0), i32 10, i32 10, i32 10, i32 10, i32 10, i32 34, i8* getelementptr inbounds ([370 x i8], [370 x i8]* @.str, i64 0, i64 0), i32 34, i32 34, i32 34, i32 10, i32 10, i32 10, i32 10, i32 10)
%8 = tail call i32 @close(i32 %6)
ret i32 0
}