#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 */
typedef int /*<<< orphan*/ vs;

/* Variables and functions */
int /*<<< orphan*/ i_d(int *);
int /*<<< orphan*/ i_set(char *, int, int /*<<< orphan*/ *,
                         int /*<<< orphan*/ *);
int sscanv(char *, int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void leak(int count) {
  char *buf = "a x8";
  char vs[8];
  int v1, v2, v3;
  int i, n;
  for (i = 0; i < count; i++) {
    n = sscanv(buf, NULL, "%% %% %% %%", i_d(&v1), i_d(&v2), i_d(&v3),
               i_set(vs, sizeof(vs), NULL, NULL));
  }
}


x86 assembly (clang, -O0):
<leak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cd <leak+0x9d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <i_d@plt>
mov    %eax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <i_d@plt>
mov    %eax,-0x34(%rbp)
lea    -0x24(%rbp),%rdi
call   1050 <i_d@plt>
mov    %eax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <i_set@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%r9d
xor    %edx,%edx
mov    %edx,%esi
lea    0xe51(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <sscanv@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114d <leak+0x1d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leak>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edi,%edi
jle    11b8 <leak+0x88>
mov    %edi,%ebx
lea    0xeb5(%rip),%rbp
lea    0xeb3(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1c(%rsp),%rdi
call   1050 <i_d@plt>
mov    %eax,%r15d
lea    0x18(%rsp),%rdi
call   1050 <i_d@plt>
mov    %eax,%r12d
lea    0x14(%rsp),%rdi
call   1050 <i_d@plt>
mov    %eax,%r13d
lea    0x20(%rsp),%rdi
mov    $0x8,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <i_set@plt>
mov    %eax,(%rsp)
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %r13d,%r9d
call   1030 <sscanv@plt>
add    $0xffffffff,%ebx
jne    1160 <leak+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"a x8\00"
@.str.1 = [12 x i8] c"%% %% %% %%\00"
define void @leak(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [8 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %8
br label %10
10: ; preds = %22, %1
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32 @i_d(i32* %5)
%17 = call i32 @i_d(i32* %6)
%18 = call i32 @i_d(i32* %7)
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%20 = call i32 @i_set(i8* %19, i32 8, i32* null, i32* null)
%21 = call i32 @sscanv(i8* %15, i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, i32 %18, i32 %20)
store i32 %21, i32* %9
br label %22
22: ; preds = %14
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
br label %10
25: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"a x8\00"
@.str.1 = [12 x i8] c"%% %% %% %%\00"
define void @leak(i32 %0) {
%2 = alloca [8 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %20
11: ; preds = %1, %11
%12 = phi i32 [ %18, %11 ], [ 0, %1 ]
%13 = call i32 @i_d(i32* %3)
%14 = call i32 @i_d(i32* %4)
%15 = call i32 @i_d(i32* %5)
%16 = call i32 @i_set(i8* %6, i32 8, i32* null, i32* null)
%17 = call i32 @sscanv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %16)
%18 = add nuw nsw i32 %12, 1
%19 = icmp eq i32 %18, %0
br i1 %19, label %20, label %11
20: ; preds = %11, %1
ret void
}