#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*/ 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];
  for (i = 0; i < width; i++) {
    buffer[i] = getc(stream);
    if (isspace(buffer[i])) {
      ungetc(buffer[i], stream);
      buffer[i] = '\0';
      break;
    }
  }
  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)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c8 <__scan_str+0x88>
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     11b5 <__scan_str+0x75>
movslq -0x14(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
jmp    11c8 <__scan_str+0x88>
jmp    11ba <__scan_str+0x7a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <__scan_str+0x1c>
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
test   %esi,%esi
jle    1193 <__scan_str+0x53>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 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    1185 <__scan_str+0x45>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <__scan_str+0x20>
jmp    1193 <__scan_str+0x53>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
movb   $0x0,(%rsp,%rbx,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
store i32 0, i32* %7
br label %9
9: ; preds = %36, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = call signext i8 @getc(i32* %14)
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = call i64 @isspace(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %13
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i32*, i32** %4
%31 = call i32 @ungetc(i8 signext %29, i32* %30)
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %33
store i8 0, i8* %34
br label %39
35: ; preds = %13
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %9
39: ; preds = %25, %9
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%41 = call i8* @strdup(i8* %40)
ret i8* %41
}

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 sgt i32 %1, 0
br i1 %6, label %7, label %22
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %19
%10 = phi i64 [ 0, %7 ], [ %20, %19 ]
%11 = tail call signext i8 @getc(i32* %0)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %10
store i8 %11, i8* %12
%13 = tail call i64 @isspace(i8 signext %11)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %9
%16 = and i64 %10, 4294967295
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %16
%18 = tail call i32 @ungetc(i8 signext %11, i32* %0)
store i8 0, i8* %17
br label %22
19: ; preds = %9
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %19, %3, %15
%23 = call i8* @strdup(i8* %5)
ret i8* %23
}