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

/* Variables and functions */
char getc(int /*<<< orphan*/ *);
scalar_t__ isspace(char);
char *strdup(char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
char *__scan_str(FILE *stream, int width, int flags) {
  int i;
  char buffer[100];
  if (width == -1) {
    width = sizeof(buffer) - 1;
  }
  for (i = 0; i < width; i++) {
    buffer[i] = getc(stream);
    if (isspace(buffer[i])) {
      ungetc(buffer[i], stream);
      break;
    }
  }
  buffer[i] = 0;
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<__scan_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1166 <__scan_str+0x26>
movl   $0x63,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <__scan_str+0x90>
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
movslq -0x14(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11bd <__scan_str+0x7d>
movslq -0x14(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
jmp    11d0 <__scan_str+0x90>
jmp    11c2 <__scan_str+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <__scan_str+0x2d>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
call   1050 <strdup@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__scan_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmp    $0xffffffff,%esi
mov    $0x63,%r15d
cmovne %esi,%r15d
test   %r15d,%r15d
jle    1198 <__scan_str+0x58>
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %al,(%rsp,%rbx,1)
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    119c <__scan_str+0x5c>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <__scan_str+0x30>
mov    %r15d,%ebx
jmp    11a6 <__scan_str+0x66>
xor    %ebx,%ebx
jmp    11a6 <__scan_str+0x66>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1050 <strdup@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @__scan_str(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 99, i32* %5
br label %12
12: ; preds = %11, %3
store i32 0, i32* %7
br label %13
13: ; preds = %37, %12
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = load i32*, i32** %4
%19 = call signext i8 @getc(i32* %18)
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i64 @isspace(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %17
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i32*, i32** %4
%35 = call i32 @ungetc(i8 signext %33, i32* %34)
br label %40
36: ; preds = %17
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %13
40: ; preds = %29, %13
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%45 = call i8* @strdup(i8* %44)
ret i8* %45
}

LLVM IR (-O2):
define noalias i8* @__scan_str(i32* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %1, -1
%7 = select i1 %6, i32 99, i32 %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %3
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %20
%12 = phi i64 [ 0, %9 ], [ %21, %20 ]
%13 = tail call signext i8 @getc(i32* %0)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %12
store i8 %13, i8* %14
%15 = tail call i64 @isspace(i8 signext %13)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = trunc i64 %12 to i32
%19 = tail call i32 @ungetc(i8 signext %13, i32* %0)
br label %23
20: ; preds = %11
%21 = add nuw nsw i64 %12, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %23, label %11
23: ; preds = %20, %3, %17
%24 = phi i32 [ %18, %17 ], [ 0, %3 ], [ %7, %20 ]
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i8* @strdup(i8* %5)
ret i8* %27
}