#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*/ b_gets(int, char *);
int /*<<< orphan*/ b_setcur(int, int);
scalar_t__ isspace(char);
void b_setline(int line) {
  int pos;
  char text[1000 - 1];
  b_gets(line, text);
  for (pos = 0; isspace(text[pos]); ++pos)
    ;
  if (text[pos] == '\0')
    pos = (pos - 1 > 0) ? pos - 1 : 0;
  b_setcur(line, pos);
}


x86 assembly (clang, -O0):
<b_setline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x3f0(%rbp),%rsi
call   1040 <b_gets@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1182 <b_setline+0x52>
jmp    1174 <b_setline+0x44>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <b_setline+0x24>
movslq -0x8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11cd <b_setline+0x9d>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jle    11b7 <b_setline+0x87>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    11c4 <b_setline+0x94>
xor    %eax,%eax
mov    %eax,-0x3f4(%rbp)
jmp    11c4 <b_setline+0x94>
mov    -0x3f4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <b_setcur@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_setline>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
call   1040 <b_gets@plt>
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%rsp,%rbx,1),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <b_setline+0x20>
mov    %ebx,%eax
test   %ebx,%ebx
mov    $0x1,%esi
cmovne %ebx,%esi
add    $0xffffffff,%esi
cmpb   $0x0,(%rsp,%rax,1)
cmovne %ebx,%esi
mov    %ebp,%edi
call   1050 <b_setcur@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @b_setline(i32 %0) {
%2 = alloca [999 x i8]
%3 = getelementptr inbounds [999 x i8], [999 x i8]* %2, i64 0, i64 0
%4 = call i32 @b_gets(i32 %0, i8* %3)
br label %5
5: ; preds = %5, %1
%6 = phi i64 [ %11, %5 ], [ 0, %1 ]
%7 = getelementptr inbounds [999 x i8], [999 x i8]* %2, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = call i64 @isspace(i8 signext %8)
%10 = icmp eq i64 %9, 0
%11 = add nuw i64 %6, 1
br i1 %10, label %12, label %5
12: ; preds = %5
%13 = trunc i64 %6 to i32
%14 = and i64 %6, 4294967295
%15 = getelementptr inbounds [999 x i8], [999 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = icmp ugt i32 %13, 1
%19 = select i1 %18, i32 %13, i32 1
%20 = add nsw i32 %19, -1
%21 = select i1 %17, i32 %20, i32 %13
%22 = call i32 @b_setcur(i32 %0, i32 %21)
ret void
}