#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 */
struct jelio_buf {
  int dummy;
};

/* Variables and functions */
scalar_t__ char_isspace(int);
int /*<<< orphan*/ jelio_buffer_getc(struct jelio_buf *);
int jelio_buffer_peekc(struct jelio_buf *);
int /*<<< orphan*/ o_c(int);
int /*<<< orphan*/ sbuprintv(char **, size_t *, size_t *, int, char *,
                             int /*<<< orphan*/);
int i_sdup_conv(void *value, int n, void *inbuf) {
  struct jelio_buf *jb = inbuf;
  char **sval = value;
  int c, count = 0, wcount = 0;
  size_t ulen, mlen;
  *sval = NULL;
  for (c = jelio_buffer_peekc(jb); char_isspace(c);
       c = jelio_buffer_peekc(jb)) {
    jelio_buffer_getc(jb);
    wcount++;
  }
  while (1) {
    c = jelio_buffer_peekc(jb);
    if (c == -1 || char_isspace(c))
      break;
    count++;
    jelio_buffer_getc(jb);
    sbuprintv(sval, &ulen, &mlen, 1024 * 1024, "%%", o_c(c));
  }
  if (!count) {
    if (c == -1)
      return -1;
    return 0;
  }
  return count + wcount;
}


x86 assembly (clang, -O0):
<i_sdup_conv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <char_isspace@plt>
cmp    $0x0,%rax
je     11cd <i_sdup_conv+0x7d>
mov    -0x28(%rbp),%rdi
call   1030 <jelio_buffer_getc@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,-0x34(%rbp)
jmp    1198 <i_sdup_conv+0x48>
jmp    11d2 <i_sdup_conv+0x82>
mov    -0x28(%rbp),%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     11fa <i_sdup_conv+0xaa>
mov    -0x34(%rbp),%edi
call   1070 <char_isspace@plt>
cmp    $0x0,%rax
je     11ff <i_sdup_conv+0xaf>
jmp    1246 <i_sdup_conv+0xf6>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <jelio_buffer_getc@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <o_c@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%r9d
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x100000,%ecx
lea    0xdc4(%rip),%r8
call   1050 <sbuprintv@plt>
jmp    11d2 <i_sdup_conv+0x82>
cmpl   $0x0,-0x38(%rbp)
jne    1272 <i_sdup_conv+0x122>
cmpl   $0xffffffff,-0x34(%rbp)
jne    1266 <i_sdup_conv+0x116>
movl   $0xffffffff,-0x4(%rbp)
jmp    127b <i_sdup_conv+0x12b>
movl   $0x0,-0x4(%rbp)
jmp    127b <i_sdup_conv+0x12b>
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i_sdup_conv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
movq   $0x0,(%rdi)
mov    %rdx,%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,%edi
call   1070 <char_isspace@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
test   %rax,%rax
je     11a1 <i_sdup_conv+0x51>
call   1030 <jelio_buffer_getc@plt>
add    $0x1,%ebx
mov    %r14,%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,%edi
call   1070 <char_isspace@plt>
jmp    1180 <i_sdup_conv+0x30>
call   1060 <jelio_buffer_peekc@plt>
cmp    $0xffffffff,%eax
je     1212 <i_sdup_conv+0xc2>
mov    %eax,%r12d
xor    %r13d,%r13d
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1070 <char_isspace@plt>
test   %rax,%rax
jne    1219 <i_sdup_conv+0xc9>
mov    %r14,%rdi
call   1030 <jelio_buffer_getc@plt>
mov    %r12d,%edi
call   1040 <o_c@plt>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
mov    %rbp,%rdx
mov    $0x100000,%ecx
lea    0xe0c(%rip),%r8
mov    %eax,%r9d
call   1050 <sbuprintv@plt>
mov    %r14,%rdi
call   1060 <jelio_buffer_peekc@plt>
mov    %eax,%r12d
add    $0xffffffff,%r13d
cmp    $0xffffffff,%eax
jne    11c0 <i_sdup_conv+0x70>
jmp    121e <i_sdup_conv+0xce>
mov    $0xffffffff,%ebx
jmp    1221 <i_sdup_conv+0xd1>
test   %r13d,%r13d
je     1232 <i_sdup_conv+0xe2>
sub    %r13d,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1221 <i_sdup_conv+0xd1>

LLVM IR (-O0):
%struct.jelio_buf = type { i32 }
@.str = [3 x i8] c"%%\00"
define i32 @i_sdup_conv(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.jelio_buf*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%15 = load i8*, i8** %7
%16 = bitcast i8* %15 to %struct.jelio_buf*
store %struct.jelio_buf* %16, %struct.jelio_buf** %8
%17 = load i8*, i8** %5
%18 = bitcast i8* %17 to i8**
store i8** %18, i8*** %9
store i32 0, i32* %11
store i32 0, i32* %12
%19 = load i8**, i8*** %9
store i8* null, i8** %19
%20 = load %struct.jelio_buf*, %struct.jelio_buf** %8
%21 = call i32 @jelio_buffer_peekc(%struct.jelio_buf* %20)
store i32 %21, i32* %10
br label %22
22: ; preds = %31, %3
%23 = load i32, i32* %10
%24 = call i64 @char_isspace(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load %struct.jelio_buf*, %struct.jelio_buf** %8
%28 = call i32 @jelio_buffer_getc(%struct.jelio_buf* %27)
%29 = load i32, i32* %12
%30 = add nsw i32 %29, 1
store i32 %30, i32* %12
br label %31
31: ; preds = %26
%32 = load %struct.jelio_buf*, %struct.jelio_buf** %8
%33 = call i32 @jelio_buffer_peekc(%struct.jelio_buf* %32)
store i32 %33, i32* %10
br label %22
34: ; preds = %22
br label %35
35: ; preds = %34, %45
%36 = load %struct.jelio_buf*, %struct.jelio_buf** %8
%37 = call i32 @jelio_buffer_peekc(%struct.jelio_buf* %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, -1
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = load i32, i32* %10
%42 = call i64 @char_isspace(i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40, %35
br label %54
45: ; preds = %40
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
%48 = load %struct.jelio_buf*, %struct.jelio_buf** %8
%49 = call i32 @jelio_buffer_getc(%struct.jelio_buf* %48)
%50 = load i8**, i8*** %9
%51 = load i32, i32* %10
%52 = call i32 @o_c(i32 %51)
%53 = call i32 @sbuprintv(i8** %50, i64* %13, i64* %14, i32 1048576, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %52)
br label %35
54: ; preds = %44
%55 = load i32, i32* %11
%56 = icmp ne i32 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = load i32, i32* %10
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 -1, i32* %4
br label %66
61: ; preds = %57
store i32 0, i32* %4
br label %66
62: ; preds = %54
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = add nsw i32 %63, %64
store i32 %65, i32* %4
br label %66
66: ; preds = %62, %61, %60
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
%struct.jelio_buf = type { i32 }
@.str = [3 x i8] c"%%\00"
define i32 @i_sdup_conv(i8* %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i8* %2 to %struct.jelio_buf*
%7 = bitcast i8* %0 to i8**
%8 = bitcast i64* %4 to i8*
%9 = bitcast i64* %5 to i8*
store i8* null, i8** %7
%10 = tail call i32 @jelio_buffer_peekc(%struct.jelio_buf* %6)
%11 = tail call i64 @char_isspace(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %17, %3
%14 = phi i32 [ 0, %3 ], [ %20, %17 ]
%15 = call i32 @jelio_buffer_peekc(%struct.jelio_buf* %6)
%16 = icmp eq i32 %15, -1
br i1 %16, label %41, label %24
17: ; preds = %3, %17
%18 = phi i32 [ %20, %17 ], [ 0, %3 ]
%19 = tail call i32 @jelio_buffer_getc(%struct.jelio_buf* %6)
%20 = add nuw nsw i32 %18, 1
%21 = tail call i32 @jelio_buffer_peekc(%struct.jelio_buf* %6)
%22 = tail call i64 @char_isspace(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %13, label %17
24: ; preds = %13, %29
%25 = phi i32 [ %34, %29 ], [ %15, %13 ]
%26 = phi i32 [ %30, %29 ], [ 0, %13 ]
%27 = call i64 @char_isspace(i32 %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = add nuw nsw i32 %26, 1
%31 = call i32 @jelio_buffer_getc(%struct.jelio_buf* %6)
%32 = call i32 @o_c(i32 %25)
%33 = call i32 @sbuprintv(i8** %7, i64* %4, i64* %5, i32 1048576, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i32 @jelio_buffer_peekc(%struct.jelio_buf* %6)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %24
36: ; preds = %29
%37 = add nuw nsw i32 %30, %14
br label %43
38: ; preds = %24
%39 = icmp eq i32 %26, 0
%40 = add nuw nsw i32 %26, %14
br i1 %39, label %41, label %43
41: ; preds = %13, %38
%42 = phi i32 [ 0, %38 ], [ -1, %13 ]
br label %43
43: ; preds = %36, %38, %41
%44 = phi i32 [ %42, %41 ], [ %40, %38 ], [ %37, %36 ]
ret i32 %44
}