#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 stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, char *, int /*<<< orphan*/, char *);
int stat(char *, struct stat *);
void SaveScreenshot() {
  char def_screenshot[20] = "z26_";
  char PCXFileName[20];
  struct stat st;
  static int PCXFileCounter = 0;
  int got;
  do {
    sprintf(PCXFileName, "%s%04i.%s", def_screenshot, PCXFileCounter++, "bmp");
    got = stat(PCXFileName, &st);
  } while (got == 0);
}


x86 assembly (clang, -O0):
<SaveScreenshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    0x2edf(%rip),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,0x2ed4(%rip)
lea    0xead(%rip),%rsi
lea    0xeb0(%rip),%r8
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1147 <SaveScreenshot+0x27>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SaveScreenshot>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
movaps 0xecc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0xecc(%rip),%r14
lea    0xecf(%rip),%r15
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
xchg   %ax,%ax
mov    0x2ece(%rip),%ecx
lea    0x1(%rcx),%eax
mov    %eax,0x2ec5(%rip)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r15,%r8
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <stat@plt>
test   %eax,%eax
je     1160 <SaveScreenshot+0x40>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.SaveScreenshot.def_screenshot = [20 x i8] c"z26_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@SaveScreenshot.PCXFileCounter = internal global i32 0
@.str = [10 x i8] c"%s%04i.%s\00"
@.str.1 = [4 x i8] c"bmp\00"
define void @SaveScreenshot() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca %struct.stat
%4 = alloca i32
%5 = bitcast [20 x i8]* %1 to i8*
br label %6
6: ; preds = %14, %0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%9 = load i32, i32* @SaveScreenshot.PCXFileCounter
%10 = add nsw i32 %9, 1
store i32 %10, i32* @SaveScreenshot.PCXFileCounter
%11 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = call i32 @stat(i8* %12, %struct.stat* %3)
store i32 %13, i32* %4
br label %14
14: ; preds = %6
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.SaveScreenshot.def_screenshot = [20 x i8] c"z26_\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@SaveScreenshot.PCXFileCounter = internal unnamed_addr global i32 0
@.str = [10 x i8] c"%s%04i.%s\00"
@.str.1 = [4 x i8] c"bmp\00"
define void @SaveScreenshot() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.stat* %3 to i8*
br label %7
7: ; preds = %7, %0
%8 = load i32, i32* @SaveScreenshot.PCXFileCounter
%9 = add nsw i32 %8, 1
store i32 %9, i32* @SaveScreenshot.PCXFileCounter
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @stat(i8* %5, %struct.stat* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %7
ret void
}