#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*/ isspace(char const);
const char *_scanf_gets(const char *str, char *dst, unsigned width,
                        int gettingChars) {
  while (width-- && (gettingChars || !isspace(*str)))
    *dst++ = *str++;
  if (!gettingChars)
    *dst = 0;
  return str;
}


x86 assembly (clang, -O0):
<_scanf_gets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     116b <_scanf_gets+0x5b>
mov    $0x1,%al
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
jne    1165 <_scanf_gets+0x55>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117b <_scanf_gets+0x6b>
jmp    11a2 <_scanf_gets+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1126 <_scanf_gets+0x16>
cmpl   $0x0,-0x18(%rbp)
jne    11b3 <_scanf_gets+0xa3>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_scanf_gets>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
test   %edx,%edx
je     1158 <_scanf_gets+0x48>
mov    %edx,%ebp
jmp    1145 <_scanf_gets+0x35>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %al,(%r14)
add    $0x1,%r14
test   %ebp,%ebp
je     1158 <_scanf_gets+0x48>
test   %r15d,%r15d
jne    1130 <_scanf_gets+0x20>
movsbl (%rbx),%edi
call   1030 <isspace@plt>
test   %eax,%eax
je     1130 <_scanf_gets+0x20>
jmp    115d <_scanf_gets+0x4d>
test   %r15d,%r15d
jne    1161 <_scanf_gets+0x51>
movb   $0x0,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @_scanf_gets(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %9
9: ; preds = %26, %4
%10 = load i32, i32* %7
%11 = add i32 %10, -1
store i32 %11, i32* %7
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i32 @isspace(i8 signext %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br label %22
22: ; preds = %16, %13
%23 = phi i1 [ true, %13 ], [ %21, %16 ]
br label %24
24: ; preds = %22, %9
%25 = phi i1 [ false, %9 ], [ %23, %22 ]
br i1 %25, label %26, label %32
26: ; preds = %24
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
%29 = load i8, i8* %27
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
store i8 %29, i8* %30
br label %9
32: ; preds = %24
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = load i8*, i8** %6
store i8 0, i8* %36
br label %37
37: ; preds = %35, %32
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
define i8* @_scanf_gets(i8* %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br label %8
8: ; preds = %6, %17
%9 = phi i32 [ %2, %6 ], [ %12, %17 ]
%10 = phi i8* [ %0, %6 ], [ %18, %17 ]
%11 = phi i8* [ %1, %6 ], [ %20, %17 ]
%12 = add i32 %9, -1
br i1 %7, label %13, label %17
13: ; preds = %8
%14 = load i8, i8* %10
%15 = tail call i32 @isspace(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %8, %13
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %10
%20 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %19, i8* %11
%21 = icmp eq i32 %12, 0
br i1 %21, label %22, label %8
22: ; preds = %17, %4
%23 = phi i8* [ %1, %4 ], [ %20, %17 ]
%24 = phi i8* [ %0, %4 ], [ %18, %17 ]
%25 = icmp eq i32 %3, 0
br i1 %25, label %26, label %29
26: ; preds = %13, %22
%27 = phi i8* [ %23, %22 ], [ %11, %13 ]
%28 = phi i8* [ %24, %22 ], [ %10, %13 ]
store i8 0, i8* %27
br label %29
29: ; preds = %26, %22
%30 = phi i8* [ %28, %26 ], [ %24, %22 ]
ret i8* %30
}