#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 */
struct dirent {
  scalar_t__ d_type;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_REG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int file_count = 0;
  DIR *dirp;
  struct dirent *entry;
  dirp = opendir("/home/samuel/sam_temp/snapshots");
  while ((entry = readdir(dirp)) != NULL) {
    if (entry->d_type == DT_REG) {
      file_count++;
    }
  }
  closedir(dirp);
  printf("\nNumber of images : %d\n", file_count);
  FILE *fHandle = NULL;
  int i = 1;
  fHandle = fopen("/home/samuel/sam_temp/pdf_config.conf", "w");
  if (fHandle != NULL) {
    printf("File created\n");
  } else {
    printf("Error Creating the file\n");
  }
  fprintf(fHandle, "/home/samuel/sam_temp\n\n");
  fprintf(fHandle, "1 \n\n");
  fprintf(fHandle, "1 \n\n");
  fprintf(fHandle, "The STAGE\n\n");
  if (file_count > 0) {
    fprintf(fHandle, "/home/samuel/sam_temp/snapshots/camera.png\n");
    fprintf(fHandle, "Screenshot : 1 \n");
    if (file_count > 1) {
      while (i < file_count) {
        fprintf(fHandle, "/home/samuel/sam_temp/snapshots/camera-%d.png\n", i);
        fprintf(fHandle, "Screenshot : %d \n", i + 1);
        i++;
      }
    }
  } else {
    fprintf(fHandle, "No image recorded\n");
  }
  fclose(fHandle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe6c(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d9 <main+0x69>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    11d4 <main+0x64>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x2d>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x14(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
lea    0xe2f(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1237 <main+0xc7>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1245 <main+0xd5>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    131b <main+0x1ab>
mov    -0x30(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x1,-0x14(%rbp)
jle    1316 <main+0x1a6>
jmp    12ca <main+0x15a>
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1311 <main+0x1a1>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ca <main+0x15a>
jmp    1316 <main+0x1a6>
jmp    132d <main+0x1bd>
mov    -0x30(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe61(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <readdir@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11db <main+0x4b>
mov    0x2e23(%rip),%rbp
nopl   (%rax)
mov    (%rax),%rax
xor    %ecx,%ecx
cmp    0x0(%rbp),%rax
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
jne    11c0 <main+0x30>
mov    %r14,%rdi
call   1070 <closedir@plt>
lea    0xe36(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3e(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
lea    0xf07(%rip),%rax
lea    0xf18(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0xe36(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
lea    0xe35(%rip),%rbp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   10b0 <fwrite@plt>
lea    0xe09(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
test   %ebx,%ebx
je     1307 <main+0x177>
lea    0xdf8(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
lea    0xe0b(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
cmp    $0x1,%ebx
je     1320 <main+0x190>
mov    $0x1,%ebp
lea    0xdf9(%rip),%r15
lea    0xe21(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
cmp    %ebp,%ebx
jne    12e0 <main+0x150>
jmp    1320 <main+0x190>
lea    0xdf9(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64 }
@.str = [32 x i8] c"/home/samuel/sam_temp/snapshots\00"
@DT_REG = global i64 0
@.str.1 = [24 x i8] c"\0ANumber of images : %d\0A\00"
@.str.2 = [38 x i8] c"/home/samuel/sam_temp/pdf_config.conf\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [14 x i8] c"File created\0A\00"
@.str.5 = [25 x i8] c"Error Creating the file\0A\00"
@.str.6 = [24 x i8] c"/home/samuel/sam_temp\0A\0A\00"
@.str.7 = [5 x i8] c"1 \0A\0A\00"
@.str.8 = [12 x i8] c"The STAGE\0A\0A\00"
@.str.9 = [44 x i8] c"/home/samuel/sam_temp/snapshots/camera.png\0A\00"
@.str.10 = [17 x i8] c"Screenshot : 1 \0A\00"
@.str.11 = [47 x i8] c"/home/samuel/sam_temp/snapshots/camera-%d.png\0A\00"
@.str.12 = [18 x i8] c"Screenshot : %d \0A\00"
@.str.13 = [19 x i8] c"No image recorded\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = call i32* @opendir(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
br label %12
12: ; preds = %25, %2
%13 = load i32*, i32** %7
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %8
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %8
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @DT_REG
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %25
25: ; preds = %22, %16
br label %12
26: ; preds = %12
%27 = load i32*, i32** %7
%28 = call i32 @closedir(i32* %27)
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32* null, i32** %9
store i32 1, i32* %10
%31 = call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %9
%32 = load i32*, i32** %9
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %38
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = load i32*, i32** %9
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32*, i32** %9
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%43 = load i32*, i32** %9
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%45 = load i32*, i32** %9
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %73
49: ; preds = %38
%50 = load i32*, i32** %9
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
%52 = load i32*, i32** %9
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%54 = load i32, i32* %6
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %72
56: ; preds = %49
br label %57
57: ; preds = %61, %56
%58 = load i32, i32* %10
%59 = load i32, i32* %6
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %71
61: ; preds = %57
%62 = load i32*, i32** %9
%63 = load i32, i32* %10
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.11, i64 0, i64 0), i32 %63)
%65 = load i32*, i32** %9
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %57
71: ; preds = %57
br label %72
72: ; preds = %71, %49
br label %76
73: ; preds = %38
%74 = load i32*, i32** %9
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %74, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %76
76: ; preds = %73, %72
%77 = load i32*, i32** %9
%78 = call i32 @fclose(i32* %77)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i64 }
@.str = [32 x i8] c"/home/samuel/sam_temp/snapshots\00"
@DT_REG = global i64 0
@.str.1 = [24 x i8] c"\0ANumber of images : %d\0A\00"
@.str.2 = [38 x i8] c"/home/samuel/sam_temp/pdf_config.conf\00"
@.str.3 = [2 x i8] c"w\00"
@.str.6 = [24 x i8] c"/home/samuel/sam_temp\0A\0A\00"
@.str.7 = [5 x i8] c"1 \0A\0A\00"
@.str.8 = [12 x i8] c"The STAGE\0A\0A\00"
@.str.9 = [44 x i8] c"/home/samuel/sam_temp/snapshots/camera.png\0A\00"
@.str.10 = [17 x i8] c"Screenshot : 1 \0A\00"
@.str.11 = [47 x i8] c"/home/samuel/sam_temp/snapshots/camera-%d.png\0A\00"
@.str.12 = [18 x i8] c"Screenshot : %d \0A\00"
@.str.13 = [19 x i8] c"No image recorded\0A\00"
@str = [24 x i8] c"Error Creating the file\00"
@str.14 = [13 x i8] c"File created\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = tail call %struct.dirent* @readdir(i32* %3)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %17, label %6
6: ; preds = %2, %6
%7 = phi %struct.dirent* [ %15, %6 ], [ %4, %2 ]
%8 = phi i32 [ %14, %6 ], [ 0, %2 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @DT_REG
%12 = icmp eq i64 %10, %11
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %8, %13
%15 = tail call %struct.dirent* @readdir(i32* %3)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %17, label %6
17: ; preds = %6, %2
%18 = phi i32 [ 0, %2 ], [ %14, %6 ]
%19 = tail call i32 @closedir(i32* %3)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
%23 = select i1 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0)
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 23, i64 1, i32* %21)
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 4, i64 1, i32* %21)
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 4, i64 1, i32* %21)
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 11, i64 1, i32* %21)
%29 = icmp eq i32 %18, 0
br i1 %29, label %40, label %30
30: ; preds = %17
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i64 43, i64 1, i32* %21)
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i64 16, i64 1, i32* %21)
%33 = icmp eq i32 %18, 1
br i1 %33, label %42, label %34
34: ; preds = %30, %34
%35 = phi i32 [ %37, %34 ], [ 1, %30 ]
%36 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.11, i64 0, i64 0), i32 %35)
%37 = add nuw i32 %35, 1
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %37, %18
br i1 %39, label %42, label %34
40: ; preds = %17
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i64 18, i64 1, i32* %21)
br label %42
42: ; preds = %34, %30, %40
%43 = tail call i32 @fclose(i32* %21)
ret i32 0
}