#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int expect_and_skip_spaces(FILE *fp, int (*space)(int)) {
  int ch, rv = 0;
  while (space((ch = fgetc(fp)))) {
    if (!rv)
      rv = 1;
  }
  ungetc(ch, fp);
  return rv;
}


x86 assembly (clang, -O0):
<expect_and_skip_spaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rax
mov    %edi,-0x14(%rbp)
call   *%rax
cmp    $0x0,%eax
je     1172 <expect_and_skip_spaces+0x52>
cmpl   $0x0,-0x18(%rbp)
jne    116d <expect_and_skip_spaces+0x4d>
movl   $0x1,-0x18(%rbp)
jmp    1137 <expect_and_skip_spaces+0x17>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <ungetc@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_and_skip_spaces>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   *%r15
xor    %ebp,%ebp
test   %eax,%eax
je     1169 <expect_and_skip_spaces+0x49>
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
test   %ebp,%ebp
cmove  %r12d,%ebp
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   *%r15
test   %eax,%eax
jne    1150 <expect_and_skip_spaces+0x30>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @expect_and_skip_spaces(i32* %0, i32 (i32)* %1) {
%3 = alloca i32*
%4 = alloca i32 (i32)*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 (i32)* %1, i32 (i32)** %4
store i32 0, i32* %6
br label %7
7: ; preds = %17, %2
%8 = load i32 (i32)*, i32 (i32)** %4
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
%11 = call i32 %8(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %13
store i32 1, i32* %6
br label %17
17: ; preds = %16, %13
br label %7
18: ; preds = %7
%19 = load i32, i32* %5
%20 = load i32*, i32** %3
%21 = call i32 @ungetc(i32 %19, i32* %20)
%22 = load i32, i32* %6
ret i32 %22
}

LLVM IR (-O2):
define i32 @expect_and_skip_spaces(i32* nocapture %0, i32 (i32)* nocapture %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = tail call i32 %1(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %9, %6 ], [ 0, %2 ]
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 1, i32 %7
%10 = tail call i32 @fgetc(i32* %0)
%11 = tail call i32 %1(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %6, %2
%14 = phi i32 [ 0, %2 ], [ %9, %6 ]
%15 = phi i32 [ %3, %2 ], [ %10, %6 ]
%16 = tail call i32 @ungetc(i32 %15, i32* %0)
ret i32 %14
}