#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, short, char, char);
short strlen(char *);
void main() {
  short int i = 0;
  char string[1000];
  FILE *file1;
  file1 = fopen("first_string", "r");
  for (i = 0; i < 1000; i++)
    string[i] = 0;
  fgets(string, 400, file1);
  for (i = 0; i < strlen(string); i++) {
    printf("char [ i = %d ] = %d in digital and %c in char;\n", i, string[i],
           string[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movw   $0x0,-0x2(%rbp)
lea    0xea8(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x3f8(%rbp)
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
cmp    $0x3e8,%eax
jge    119e <main+0x5e>
movswq -0x2(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    1171 <main+0x31>
lea    -0x3f0(%rbp),%rdi
mov    -0x3f8(%rbp),%rdx
mov    $0x190,%esi
call   1050 <fgets@plt>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
mov    %eax,-0x3fc(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %ax,%cx
mov    -0x3fc(%rbp),%eax
movswl %cx,%ecx
cmp    %ecx,%eax
jge    1226 <main+0xe6>
mov    -0x2(%rbp),%dx
movswq -0x2(%rbp),%rax
mov    -0x3f0(%rbp,%rax,1),%cl
movswq -0x2(%rbp),%rax
lea    0xe0d(%rip),%rdi
movswl %dx,%esi
movsbl %cl,%edx
movsbl -0x3f0(%rbp,%rax,1),%ecx
ff
call   1040 <printf@plt>
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    11bc <main+0x7c>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    $0x3e8,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rdi
mov    $0x190,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %ax,%ax
jle    11d6 <main+0x86>
xor    %ebx,%ebx
lea    0xe65(%rip),%r14
mov    %rsp,%r15
nopl   (%rax)
movsbl (%rsp,%rbx,1),%ecx
movswl %bx,%esi
mov    %r14,%rdi
mov    %ecx,%edx
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
movswq %ax,%rax
cmp    %rax,%rbx
jl     11b0 <main+0x60>
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"first_string\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [49 x i8] c"char [ i = %d ] = %d in digital and %c in char;\0A\00"
define void @main() {
%1 = alloca i16
%2 = alloca [1000 x i8]
%3 = alloca i32*
store i16 0, i16* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
store i16 0, i16* %1
br label %5
5: ; preds = %13, %0
%6 = load i16, i16* %1
%7 = sext i16 %6 to i32
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = load i16, i16* %1
%11 = sext i16 %10 to i64
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %9
%14 = load i16, i16* %1
%15 = add i16 %14, 1
store i16 %15, i16* %1
br label %5
16: ; preds = %5
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i32 @fgets(i8* %17, i32 400, i32* %18)
store i16 0, i16* %1
br label %20
20: ; preds = %38, %16
%21 = load i16, i16* %1
%22 = sext i16 %21 to i32
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%24 = call signext i16 @strlen(i8* %23)
%25 = sext i16 %24 to i32
%26 = icmp slt i32 %22, %25
br i1 %26, label %27, label %41
27: ; preds = %20
%28 = load i16, i16* %1
%29 = load i16, i16* %1
%30 = sext i16 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i16, i16* %1
%34 = sext i16 %33 to i64
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i16 signext %28, i8 signext %32, i8 signext %36)
br label %38
38: ; preds = %27
%39 = load i16, i16* %1
%40 = add i16 %39, 1
store i16 %40, i16* %1
br label %20
41: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"first_string\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [49 x i8] c"char [ i = %d ] = %d in digital and %c in char;\0A\00"
define void @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @fgets(i8* %3, i32 400, i32* %4)
%6 = call signext i16 @strlen(i8* %3)
%7 = icmp sgt i16 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %0, %8
%9 = phi i64 [ %14, %8 ], [ 0, %0 ]
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = trunc i64 %9 to i16
%13 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i16 signext %12, i8 signext %11, i8 signext %11)
%14 = add nuw nsw i64 %9, 1
%15 = call signext i16 @strlen(i8* %3)
%16 = sext i16 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %8, label %18
18: ; preds = %8, %0
ret void
}