#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, int,
                           int, int, int, int, int, int);
int /*<<< orphan*/ free(char *);
int open(char *, int, int);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ system(char *);
int main(int ac, char **av) {
  (void)ac;
  char *str =
      "#include <unistd.h>%c#include <stdlib.h>%c#include <fcntl.h>%c#include "
      "<stdio.h>%c#include <string.h>%cint main(int ac, char "
      "**av){(void)ac;char *str=%c%s%c;%cint i = %d;%cchar "
      "*sully;sully=strdup(%cSully__.c%c);if((strcmp(*av,%c./"
      "Sully%c)))--i;sully[6]='0'+i;int fd=open(sully, O_CREAT|O_TRUNC|O_RDWR, "
      "0644);free(sully);dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 10, "
      "i, 10, 34, 34, 34, 34, 34, 34, 34, 34, 10, 10, 10, "
      "10);close(fd);sully=strdup(%cclang -Wall -Wextra -Werror Sully__.c -o "
      "Sully__%c);sully[34]='0'+i;sully[47]='0'+i;system(sully);free(sully);"
      "sully=strdup(%c./"
      "Sully__%c);sully[8]='0'+i;if(i>0)system(sully);free(sully);return "
      "0;}%c/*%c   Comment out of functions%c*/%c";
  int i = 5;
  char *sully;
  sully = strdup("Sully__.c");
  if ((strcmp(*av, "./Sully")))
    --i;
  sully[6] = '0' + i;
  int fd = open(sully, O_CREAT | O_TRUNC | O_RDWR, 0644);
  free(sully);
  dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 10, i, 10, 34, 34, 34, 34,
          34, 34, 34, 34, 10, 10, 10, 10);
  close(fd);
  sully = strdup("clang -Wall -Wextra -Werror Sully__.c -o Sully__");
  sully[34] = '0' + i;
  sully[47] = '0' + i;
  system(sully);
  free(sully);
  sully = strdup("./Sully__");
  sully[8] = '0' + i;
  if (i > 0)
    system(sully);
  free(sully);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
lea    0x1111(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0x1104(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11d1 <main+0x61>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x28(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
or     (%rax),%esi
mov    0x2ddb(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%r10
mov    -0x1c(%rbp),%eax
mov    $0xa,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0xa,(%rsp)
movl   $0x22,0x8(%rsp)
mov    %r10,0x10(%rsp)
movl   $0x22,0x18(%rsp)
movl   $0xa,0x20(%rsp)
mov    %eax,0x28(%rsp)
movl   $0xa,0x30(%rsp)
movl   $0x22,0x38(%rsp)
movl   $0x22,0x40(%rsp)
movl   $0x22,0x48(%rsp)
movl   $0x22,0x50(%rsp)
movl   $0x22,0x58(%rsp)
movl   $0x22,0x60(%rsp)
movl   $0x22,0x68(%rsp)
movl   $0x22,0x70(%rsp)
movl   $0xa,0x78(%rsp)
movl   $0xa,0x80(%rsp)
movl   $0xa,0x88(%rsp)
movl   $0xa,0x90(%rsp)
call   1060 <dprintf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
lea    0xfe6(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x22(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2f(%rax)
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xfd7(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x8(%rax)
cmpl   $0x0,-0x1c(%rbp)
jle    134a <main+0x1da>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0x1132(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rdi
lea    0x1129(%rip),%rsi
call   1070 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
or     $0x4,%ebp
lea    0x30(%rbp),%r15d
mov    0x2e48(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r15b,0x6(%rbx)
mov    0x2e12(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
sub    $0x8,%rsp
lea    0xe15(%rip),%rsi
mov    %r14d,%edi
mov    $0xa,%edx
mov    $0xa,%ecx
mov    $0xa,%r8d
mov    $0xa,%r9d
push   $0xa
push   $0xa
push   $0xa
push   $0xa
push   $0x22
push   $0x22
push   $0x22
push   $0x22
push   $0x22
push   $0x22
push   $0x22
push   $0x22
push   $0xa
push   %rbp
push   $0xa
push   $0x22
push   %rsi
push   $0x22
push   $0xa
call   1060 <dprintf@plt>
add    $0xa0,%rsp
mov    %r14d,%edi
call   1050 <close@plt>
lea    0x1082(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r15b,0x22(%rax)
mov    %r15b,0x2f(%rax)
mov    %rax,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x108c(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r15b,0x8(%rax)
mov    %rax,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [691 x i8] c"#include <unistd.h>%c#include <stdlib.h>%c#include <fcntl.h>%c#include <stdio.h>%c#include <string.h>%cint main(int ac, char **av){(void)ac;char *str=%c%s%c;%cint i = %d;%cchar *sully;sully=strdup(%cSully__.c%c);if((strcmp(*av,%c./Sully%c)))--i;sully[6]='0'+i;int fd=open(sully, O_CREAT|O_TRUNC|O_RDWR, 0644);free(sully);dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 10, i, 10, 34, 34, 34, 34, 34, 34, 34, 34, 10, 10, 10, 10);close(fd);sully=strdup(%cclang -Wall -Wextra -Werror Sully__.c -o Sully__%c);sully[34]='0'+i;sully[47]='0'+i;system(sully);free(sully);sully=strdup(%c./Sully__%c);sully[8]='0'+i;if(i>0)system(sully);free(sully);return 0;}%c/*%c Comment out of functions%c*/%c\00"
@.str.1 = [10 x i8] c"Sully__.c\00"
@.str.2 = [8 x i8] c"./Sully\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.3 = [49 x i8] c"clang -Wall -Wextra -Werror Sully__.c -o Sully__\00"
@.str.4 = [10 x i8] c"./Sully__\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
store i8* getelementptr inbounds ([691 x i8], [691 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 5, i32* %7
%11 = call i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* %7
%18 = add nsw i32 %17, -1
store i32 %18, i32* %7
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* %7
%21 = add nsw i32 48, %20
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 6
store i8 %22, i8* %24
%25 = load i8*, i8** %8
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
%29 = load i32, i32* @O_RDWR
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %25, i32 %30, i32 420)
store i32 %31, i32* %9
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* %9
%35 = load i8*, i8** %6
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @dprintf(i32 %34, i8* %35, i32 10, i32 10, i32 10, i32 10, i32 10, i32 34, i8* %36, i32 34, i32 10, i32 %37, i32 10, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 10, i32 10, i32 10, i32 10)
%39 = load i32, i32* %9
%40 = call i32 @close(i32 %39)
%41 = call i8* @strdup(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
store i8* %41, i8** %8
%42 = load i32, i32* %7
%43 = add nsw i32 48, %42
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i64 34
store i8 %44, i8* %46
%47 = load i32, i32* %7
%48 = add nsw i32 48, %47
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 47
store i8 %49, i8* %51
%52 = load i8*, i8** %8
%53 = call i32 @system(i8* %52)
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
%56 = call i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i8* %56, i8** %8
%57 = load i32, i32* %7
%58 = add nsw i32 48, %57
%59 = trunc i32 %58 to i8
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 8
store i8 %59, i8* %61
%62 = load i32, i32* %7
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %19
%65 = load i8*, i8** %8
%66 = call i32 @system(i8* %65)
br label %67
67: ; preds = %64, %19
%68 = load i8*, i8** %8
%69 = call i32 @free(i8* %68)
ret i32 0
}

LLVM IR (-O2):
@.str = [691 x i8] c"#include <unistd.h>%c#include <stdlib.h>%c#include <fcntl.h>%c#include <stdio.h>%c#include <string.h>%cint main(int ac, char **av){(void)ac;char *str=%c%s%c;%cint i = %d;%cchar *sully;sully=strdup(%cSully__.c%c);if((strcmp(*av,%c./Sully%c)))--i;sully[6]='0'+i;int fd=open(sully, O_CREAT|O_TRUNC|O_RDWR, 0644);free(sully);dprintf(fd, str, 10, 10, 10, 10, 10, 34, str, 34, 10, i, 10, 34, 34, 34, 34, 34, 34, 34, 34, 10, 10, 10, 10);close(fd);sully=strdup(%cclang -Wall -Wextra -Werror Sully__.c -o Sully__%c);sully[34]='0'+i;sully[47]='0'+i;system(sully);free(sully);sully=strdup(%c./Sully__%c);sully[8]='0'+i;if(i>0)system(sully);free(sully);return 0;}%c/*%c Comment out of functions%c*/%c\00"
@.str.1 = [10 x i8] c"Sully__.c\00"
@.str.2 = [8 x i8] c"./Sully\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.3 = [49 x i8] c"clang -Wall -Wextra -Werror Sully__.c -o Sully__\00"
@.str.4 = [10 x i8] c"./Sully__\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%4 = load i8*, i8** %1
%5 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i32 5, i32 4
%8 = trunc i32 %7 to i8
%9 = or i8 %8, 48
%10 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %9, i8* %10
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %12, %11
%14 = load i32, i32* @O_RDWR
%15 = or i32 %13, %14
%16 = tail call i32 @open(i8* %3, i32 %15, i32 420)
%17 = tail call i32 @free(i8* %3)
%18 = tail call i32 @dprintf(i32 %16, i8* getelementptr inbounds ([691 x i8], [691 x i8]* @.str, i64 0, i64 0), i32 10, i32 10, i32 10, i32 10, i32 10, i32 34, i8* getelementptr inbounds ([691 x i8], [691 x i8]* @.str, i64 0, i64 0), i32 34, i32 10, i32 %7, i32 10, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 34, i32 10, i32 10, i32 10, i32 10)
%19 = tail call i32 @close(i32 %16)
%20 = tail call dereferenceable_or_null(49) i8* @strdup(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds i8, i8* %20, i64 34
store i8 %9, i8* %21
%22 = getelementptr inbounds i8, i8* %20, i64 47
store i8 %9, i8* %22
%23 = tail call i32 @system(i8* %20)
%24 = tail call i32 @free(i8* %20)
%25 = tail call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%26 = getelementptr inbounds i8, i8* %25, i64 8
store i8 %9, i8* %26
%27 = tail call i32 @system(i8* %25)
%28 = tail call i32 @free(i8* %25)
ret i32 0
}