#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 */
char *itoa(unsigned int, char *, int);
int /*<<< orphan*/ save_screen(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int screenshot(void) {
  static unsigned frame_nr = 1;
  char btxt1[32], btxt2[32];
  if (frame_nr < 10)
    strcpy(btxt1, "0000");
  else if (frame_nr < 100)
    strcpy(btxt1, "000");
  else if (frame_nr < 1000)
    strcpy(btxt1, "00");
  else if (frame_nr < 10000)
    strcpy(btxt1, "0");
  else
    return 0;
  strcat(btxt1, itoa(frame_nr, btxt2, 10));
  strcat(btxt1, ".bmp");
  if (!save_screen(btxt1))
    return 0;
  frame_nr++;
  return 1;
}


x86 assembly (clang, -O0):
<screenshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
cmpl   $0xa,0x2ef1(%rip)
jae    116a <screenshot+0x2a>
lea    -0x30(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f1 <screenshot+0xb1>
cmpl   $0x64,0x2ecf(%rip)
jae    118c <screenshot+0x4c>
lea    -0x30(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11ec <screenshot+0xac>
cmpl   $0x3e8,0x2eaa(%rip)
jae    11b1 <screenshot+0x71>
lea    -0x30(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11e7 <screenshot+0xa7>
cmpl   $0x2710,0x2e85(%rip)
jae    11d6 <screenshot+0x96>
lea    -0x30(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11e2 <screenshot+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    125d <screenshot+0x11d>
jmp    11e7 <screenshot+0xa7>
jmp    11ec <screenshot+0xac>
jmp    11f1 <screenshot+0xb1>
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2e41(%rip),%edi
lea    -0x50(%rbp),%rsi
mov    $0xa,%edx
call   1060 <itoa@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   1050 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x30(%rbp),%rdi
call   1040 <save_screen@plt>
cmp    $0x0,%eax
jne    1247 <screenshot+0x107>
movl   $0x0,-0x4(%rbp)
jmp    125d <screenshot+0x11d>
mov    0x2df3(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dea(%rip)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<screenshot>:
push   %rbx
sub    $0x40,%rsp
mov    0x2ef5(%rip),%ecx
cmp    $0xa,%ecx
jae    1159 <screenshot+0x19>
lea    0xea9(%rip),%rsi
jmp    1189 <screenshot+0x49>
cmp    $0x64,%ecx
jae    1167 <screenshot+0x27>
lea    0xe9c(%rip),%rsi
jmp    1189 <screenshot+0x49>
cmp    $0x3e8,%ecx
jae    1178 <screenshot+0x38>
lea    0xe8c(%rip),%rsi
jmp    1189 <screenshot+0x49>
xor    %eax,%eax
cmp    $0x270f,%ecx
ja     11df <screenshot+0x9f>
lea    0xe7a(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x2ea4(%rip),%edi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1060 <itoa@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <strcat@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1040 <save_screen@plt>
test   %eax,%eax
je     11dd <screenshot+0x9d>
addl   $0x1,0x2e6a(%rip)
mov    $0x1,%eax
jmp    11df <screenshot+0x9f>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@screenshot.frame_nr = internal global i32 1
@.str = [5 x i8] c"0000\00"
@.str.1 = [4 x i8] c"000\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [5 x i8] c".bmp\00"
define i32 @screenshot() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = load i32, i32* @screenshot.frame_nr
%5 = icmp ult i32 %4, 10
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %31
9: ; preds = %0
%10 = load i32, i32* @screenshot.frame_nr
%11 = icmp ult i32 %10, 100
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %30
15: ; preds = %9
%16 = load i32, i32* @screenshot.frame_nr
%17 = icmp ult i32 %16, 1000
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %29
21: ; preds = %15
%22 = load i32, i32* @screenshot.frame_nr
%23 = icmp ult i32 %22, 10000
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %28
27: ; preds = %21
store i32 0, i32* %1
br label %46
28: ; preds = %24
br label %29
29: ; preds = %28, %18
br label %30
30: ; preds = %29, %12
br label %31
31: ; preds = %30, %6
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%33 = load i32, i32* @screenshot.frame_nr
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%35 = call i8* @itoa(i32 %33, i8* %34, i32 10)
%36 = call i32 @strcat(i8* %32, i8* %35)
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%38 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%40 = call i32 @save_screen(i8* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %31
store i32 0, i32* %1
br label %46
43: ; preds = %31
%44 = load i32, i32* @screenshot.frame_nr
%45 = add i32 %44, 1
store i32 %45, i32* @screenshot.frame_nr
store i32 1, i32* %1
br label %46
46: ; preds = %43, %42, %27
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@screenshot.frame_nr = internal unnamed_addr global i32 1
@.str = [5 x i8] c"0000\00"
@.str.1 = [4 x i8] c"000\00"
@.str.2 = [3 x i8] c"00\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [5 x i8] c".bmp\00"
define i32 @screenshot() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @screenshot.frame_nr
%6 = icmp ult i32 %5, 10
br i1 %6, label %13, label %7
7: ; preds = %0
%8 = icmp ult i32 %5, 100
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = icmp ult i32 %5, 1000
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = icmp ult i32 %5, 10000
br i1 %12, label %13, label %25
13: ; preds = %11, %9, %7, %0
%14 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %11 ]
%15 = call i32 @strcpy(i8* %3, i8* %14)
%16 = load i32, i32* @screenshot.frame_nr
%17 = call i8* @itoa(i32 %16, i8* %4, i32 10)
%18 = call i32 @strcat(i8* %3, i8* %17)
%19 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @save_screen(i8* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = load i32, i32* @screenshot.frame_nr
%24 = add i32 %23, 1
store i32 %24, i32* @screenshot.frame_nr
br label %25
25: ; preds = %13, %11, %22
%26 = phi i32 [ 1, %22 ], [ 0, %11 ], [ 0, %13 ]
ret i32 %26
}