#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 */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
unsigned int strlen(char const *);
void check(const char *buf) {
  int count = 0;
  unsigned int i = 0;
  char c[2] = {0};
  int j;
  while (i < strlen(buf)) {
    c[0] = buf[i];
    sscanf(c, "%d", &j);
    count += j;
    if (count == 15) {
      printf("Password ok!\n");
      exit(0);
    }
    ++i;
  }
  printf("Password Incorrect!\n");
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    11eb <check+0x9b>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
lea    -0x12(%rbp),%rdi
lea    0xe52(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xf,-0xc(%rbp)
jne    11dd <check+0x8d>
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <check+0x2a>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
movw   $0x0,0x2(%rsp)
call   1040 <strlen@plt>
test   %eax,%eax
je     11b4 <check+0x74>
xor    %ebx,%ebx
lea    0xe99(%rip),%r14
lea    0x2(%rsp),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x0(%r13,%rbx,1),%eax
mov    %al,0x2(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
add    0x4(%rsp),%ebp
cmp    $0xf,%ebp
je     11cf <check+0x8f>
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1180 <check+0x40>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [14 x i8] c"Password ok!\0A\00"
@.str.2 = [21 x i8] c"Password Incorrect!\0A\00"
define void @check(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8]
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = bitcast [2 x i8]* %5 to i8*
br label %8
8: ; preds = %30, %1
%9 = load i32, i32* %4
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = icmp ult i32 %9, %11
br i1 %12, label %13, label %33
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %18, i8* %19
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%22 = load i32, i32* %6
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %22
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 15
br i1 %26, label %27, label %30
27: ; preds = %13
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %13
%31 = load i32, i32* %4
%32 = add i32 %31, 1
store i32 %32, i32* %4
br label %8
33: ; preds = %8
%34 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [20 x i8] c"Password Incorrect!\00"
@str.3 = [13 x i8] c"Password ok!\00"
define void @check(i8* %0) {
%2 = alloca i16
%3 = alloca i32
%4 = bitcast i16* %2 to i8*
store i16 0, i16* %2
%5 = bitcast i32* %3 to i8*
%6 = call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %12
8: ; preds = %12
%9 = call i32 @strlen(i8* %0)
%10 = zext i32 %9 to i64
%11 = icmp ult i64 %21, %10
br i1 %11, label %12, label %25
12: ; preds = %1, %8
%13 = phi i64 [ %21, %8 ], [ 0, %1 ]
%14 = phi i32 [ %19, %8 ], [ 0, %1 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
store i8 %16, i8* %4
%17 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %14
%20 = icmp eq i32 %19, 15
%21 = add nuw nsw i64 %13, 1
br i1 %20, label %22, label %8
22: ; preds = %12
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %8, %1
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
ret void
}