#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 */
void *bmp_to_buffer_800x480_16bits(int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ save_bmp(char *, int, int, void *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void test_bmp_to_buffer_800x480_16bits(void) {
  void *buffer = NULL;
  int i;
  char outpath[256] = {0};
  for (i = 0; i < 30; i++) {
    buffer = bmp_to_buffer_800x480_16bits(i);
    if (buffer) {
      sprintf(outpath, "%s/%d.bmp", "/mnt/sdcard", i + 1);
      save_bmp(outpath, 800, 480, buffer, 16);
      free(buffer);
    }
  }
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movq   $0x0,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1e,-0xc(%rbp)
jge    11fa <test_bmp_to_buffer_800x480_16bits+0xaa>
mov    -0xc(%rbp),%edi
call   1050 <bmp_to_buffer_800x480_16bits@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e7 <test_bmp_to_buffer_800x480_16bits+0x97>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
lea    0xe4e(%rip),%rsi
lea    0xe51(%rip),%rdx
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x320,%esi
mov    $0x1e0,%edx
mov    $0x10,%r8d
call   1060 <save_bmp@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    11ec <test_bmp_to_buffer_800x480_16bits+0x9c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <test_bmp_to_buffer_800x480_16bits+0x2d>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    $0x1,%ebx
lea    0xe3a(%rip),%r14
lea    0xe3d(%rip),%r15
mov    %rsp,%r12
jmp    11e8 <test_bmp_to_buffer_800x480_16bits+0xa8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    $0x1f,%ebx
je     122d <test_bmp_to_buffer_800x480_16bits+0xed>
lea    -0x1(%rbx),%edi
call   1040 <bmp_to_buffer_800x480_16bits@plt>
test   %rax,%rax
je     11e0 <test_bmp_to_buffer_800x480_16bits+0xa0>
mov    %rax,%r13
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1060 <sprintf@plt>
mov    %r12,%rdi
mov    $0x320,%esi
mov    $0x1e0,%edx
mov    %r13,%rcx
mov    $0x10,%r8d
call   1050 <save_bmp@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11e0 <test_bmp_to_buffer_800x480_16bits+0xa0>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s/%d.bmp\00"
@.str.1 = [12 x i8] c"/mnt/sdcard\00"
define void @test_bmp_to_buffer_800x480_16bits() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [256 x i8]
store i8* null, i8** %1
%4 = bitcast [256 x i8]* %3 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 30
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i8* @bmp_to_buffer_800x480_16bits(i32 %9)
store i8* %10, i8** %1
%11 = load i8*, i8** %1
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = load i8*, i8** %1
%20 = call i32 @save_bmp(i8* %18, i32 800, i32 480, i8* %19, i32 16)
%21 = load i8*, i8** %1
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %13, %8
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %5
27: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s/%d.bmp\00"
@.str.1 = [12 x i8] c"/mnt/sdcard\00"
define void @test_bmp_to_buffer_800x480_16bits() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %12
%4 = phi i32 [ 0, %0 ], [ %7, %12 ]
%5 = call i8* @bmp_to_buffer_800x480_16bits(i32 %4)
%6 = icmp eq i8* %5, null
%7 = add nuw nsw i32 %4, 1
br i1 %6, label %12, label %8
8: ; preds = %3
%9 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%10 = call i32 @save_bmp(i8* %2, i32 800, i32 480, i8* %5, i32 16)
%11 = call i32 @free(i8* %5)
br label %12
12: ; preds = %3, %8
%13 = icmp eq i32 %7, 30
br i1 %13, label %14, label %3
14: ; preds = %12
ret void
}