#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*/ naive_isspace(char);
scalar_t__ read_char(char *);
int /*<<< orphan*/ read_space();
int /*<<< orphan*/ unread_char(char);
int read_string(char *s) {
  int flag = 0;
  char c = '\0';
  read_space();
  while (read_char(&c) && !naive_isspace(c)) {
    *s++ = c;
    flag = 1;
  }
  if (c)
    unread_char(c);
  if (flag)
    *s = '\0';
  return flag;
}


x86 assembly (clang, -O0):
<read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    $0x0,%al
call   1040 <read_space@plt>
lea    -0xd(%rbp),%rdi
call   1050 <read_char@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xe(%rbp)
je     118d <read_string+0x4d>
movsbl -0xd(%rbp),%edi
call   1030 <naive_isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    119d <read_string+0x5d>
jmp    11bd <read_string+0x7d>
mov    -0xd(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movl   $0x1,-0xc(%rbp)
jmp    115e <read_string+0x1e>
cmpb   $0x0,-0xd(%rbp)
je     11d0 <read_string+0x90>
movsbl -0xd(%rbp),%edi
call   1060 <unread_char@plt>
cmpl   $0x0,-0xc(%rbp)
je     11e1 <read_string+0xa1>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <read_space@plt>
lea    0xf(%rsp),%rdi
call   1050 <read_char@plt>
mov    $0x1,%r14b
test   %rax,%rax
je     11bd <read_string+0x7d>
movsbl 0xf(%rsp),%edi
call   1030 <naive_isspace@plt>
test   %eax,%eax
jne    11bd <read_string+0x7d>
add    $0x1,%rbx
lea    0xf(%rsp),%r14
mov    %rbx,%rcx
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rbx
movzbl 0xf(%rsp),%eax
mov    %al,-0x1(%rcx)
mov    %r14,%rdi
call   1050 <read_char@plt>
test   %rax,%rax
je     11ba <read_string+0x7a>
movsbl 0xf(%rsp),%edi
call   1030 <naive_isspace@plt>
lea    0x1(%rbx),%rcx
test   %eax,%eax
je     1190 <read_string+0x50>
xor    %r14d,%r14d
mov    0xf(%rsp),%al
test   %al,%al
je     11cd <read_string+0x8d>
movsbl %al,%edi
call   1060 <unread_char@plt>
test   %r14b,%r14b
jne    11d5 <read_string+0x95>
movb   $0x0,(%rbx)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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