#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 */
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int fgetcnum(FILE *file, int num) {
  int i;
  char out;
  for (i = 0; i < num - 2; i++) {
    out = fgetc(file);
    printf("File Char: %c\n", out);
  }
  out = fgetc(file);
  return out - '0';
}


x86 assembly (clang, -O0):
<fgetcnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1171 <fgetcnum+0x51>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
lea    0xea6(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <fgetcnum+0x16>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
sub    $0x30,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetcnum>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
cmp    $0x3,%esi
jl     1158 <fgetcnum+0x38>
mov    %esi,%ebp
add    $0xfffffffe,%ebp
lea    0xec8(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    1140 <fgetcnum+0x20>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
movsbl %al,%eax
add    $0xffffffd0,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"File Char: %c\0A\00"
define i32 @fgetcnum(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 2
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %6
%15 = load i8, i8* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %15)
br label %17
17: ; preds = %12
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
%21 = load i32*, i32** %3
%22 = call signext i8 @fgetc(i32* %21)
store i8 %22, i8* %6
%23 = load i8, i8* %6
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 48
ret i32 %25
}

LLVM IR (-O2):
@.str = [15 x i8] c"File Char: %c\0A\00"
define i32 @fgetcnum(i32* nocapture %0, i32 %1) {
%3 = add i32 %1, -2
%4 = icmp sgt i32 %1, 2
br i1 %4, label %5, label %11
5: ; preds = %2, %5
%6 = phi i32 [ %9, %5 ], [ 0, %2 ]
%7 = tail call signext i8 @fgetc(i32* %0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%9 = add nuw nsw i32 %6, 1
%10 = icmp eq i32 %9, %3
br i1 %10, label %11, label %5
11: ; preds = %5, %2
%12 = tail call signext i8 @fgetc(i32* %0)
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, -48
ret i32 %14
}