#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 */
int EOF;
int get_next_non_space_char(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isspace(int);
int get_next_token(FILE *fp, char *buf, size_t size) {
  int i = 0;
  int c = get_next_non_space_char(fp);
  while (c != EOF && !isspace(c) && i < size - 1) {
    buf[i++] = c;
    c = getc(fp);
  }
  buf[i] = 0;
  return i;
}


x86 assembly (clang, -O0):
<get_next_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_next_non_space_char@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
mov    0x2e85(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     119b <get_next_token+0x6b>
mov    -0x20(%rbp),%edi
call   1030 <isspace@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    119b <get_next_token+0x6b>
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ab <get_next_token+0x7b>
jmp    11d6 <get_next_token+0xa6>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x20(%rbp)
jmp    1157 <get_next_token+0x27>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_token>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <get_next_non_space_char@plt>
mov    %eax,%ebp
mov    0x2e96(%rip),%r15
xor    %eax,%eax
cmp    (%r15),%ebp
je     119f <get_next_token+0x6f>
lea    -0x1(%rbx),%r13
mov    %ebx,%eax
add    $0xffffffff,%eax
mov    %eax,0x4(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <isspace@plt>
test   %eax,%eax
jne    1197 <get_next_token+0x67>
cmp    %rbx,%r13
je     119b <get_next_token+0x6b>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1170 <get_next_token+0x40>
mov    %ebx,%eax
jmp    119f <get_next_token+0x6f>
mov    0x4(%rsp),%eax
mov    %eax,%ecx
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @get_next_token(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%9 = load i32*, i32** %4
%10 = call i32 @get_next_non_space_char(i32* %9)
store i32 %10, i32* %8
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %8
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %8
%17 = call i32 @isspace(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = load i64, i64* %6
%23 = sub i64 %22, 1
%24 = icmp ult i64 %21, %23
br label %25
25: ; preds = %19, %15, %11
%26 = phi i1 [ false, %15 ], [ false, %11 ], [ %24, %19 ]
br i1 %26, label %27, label %37
27: ; preds = %25
%28 = load i32, i32* %8
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = load i32*, i32** %4
%36 = call i32 @getc(i32* %35)
store i32 %36, i32* %8
br label %11
37: ; preds = %25
%38 = load i8*, i8** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* %7
ret i32 %42
}

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