#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 __instr {
  int dummy;
};

/* Variables and functions */
int EOF;
int __instr_getc(struct __instr *);
int __scanf_conv_chars(struct __instr *_is, int count, char *outp) {
  while (count--) {
    int c = __instr_getc(_is);
    if (c == EOF)
      return -1;
    if (outp != NULL)
      *outp++ = c;
  };
  return 0;
}


x86 assembly (clang, -O0):
<__scanf_conv_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1187 <__scanf_conv_chars+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <__instr_getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    1161 <__scanf_conv_chars+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <__scanf_conv_chars+0x7e>
cmpq   $0x0,-0x20(%rbp)
je     1182 <__scanf_conv_chars+0x72>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1123 <__scanf_conv_chars+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__scanf_conv_chars>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1155 <__scanf_conv_chars+0x45>
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2ebe(%rip),%r15
jmp    113a <__scanf_conv_chars+0x2a>
nopl   0x0(%rax)
mov    %al,(%rbx)
add    $0x1,%rbx
test   %ebp,%ebp
je     1155 <__scanf_conv_chars+0x45>
mov    %r14,%rdi
call   1030 <__instr_getc@plt>
cmp    (%r15),%eax
je     1159 <__scanf_conv_chars+0x49>
add    $0xffffffff,%ebp
test   %rbx,%rbx
jne    1130 <__scanf_conv_chars+0x20>
xor    %ebx,%ebx
test   %ebp,%ebp
jne    113a <__scanf_conv_chars+0x2a>
xor    %eax,%eax
jmp    115e <__scanf_conv_chars+0x4e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.__instr = type { i32 }
@EOF = global i32 0
define i32 @__scanf_conv_chars(%struct.__instr* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.__instr*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.__instr* %0, %struct.__instr** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
br label %9
9: ; preds = %28, %3
%10 = load i32, i32* %6
%11 = add nsw i32 %10, -1
store i32 %11, i32* %6
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load %struct.__instr*, %struct.__instr** %5
%15 = call i32 @__instr_getc(%struct.__instr* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %4
br label %30
20: ; preds = %13
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %8
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %7
store i8 %25, i8* %26
br label %28
28: ; preds = %23, %20
br label %9
29: ; preds = %9
store i32 0, i32* %4
br label %30
30: ; preds = %29, %19
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.__instr = type { i32 }
@EOF = global i32 0
define i32 @__scanf_conv_chars(%struct.__instr* %0, i32 %1, i8* writeonly %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %20, label %5
5: ; preds = %3, %17
%6 = phi i32 [ %8, %17 ], [ %1, %3 ]
%7 = phi i8* [ %18, %17 ], [ %2, %3 ]
%8 = add nsw i32 %6, -1
%9 = tail call i32 @__instr_getc(%struct.__instr* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %20, label %12
12: ; preds = %5
%13 = icmp eq i8* %7, null
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = trunc i32 %9 to i8
%16 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %15, i8* %7
br label %17
17: ; preds = %12, %14
%18 = phi i8* [ %16, %14 ], [ null, %12 ]
%19 = icmp eq i32 %8, 0
br i1 %19, label %20, label %5
20: ; preds = %17, %5, %3
%21 = phi i32 [ 0, %3 ], [ -1, %5 ], [ 0, %17 ]
ret i32 %21
}