#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  char c, corrected = 'o';
  FILE *input, *output;
  if ((input = fopen("greski.txt", "r")) == NULL) {
    printf("I can't open it!");
    return -1;
  }
  if ((output = fopen("greski_out.txt", "w")) == NULL) {
    printf("I can't open it!");
    return -1;
  }
  while ((c = fgetc(input)) != EOF) {
    if (c == '0')
      fputc(corrected, output);
    else
      fputc(c, output);
  }
  fclose(input);
  fclose(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x6f,-0x6(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119c <main+0x4c>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <main+0xf9>
lea    0xe7b(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d5 <main+0x85>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <main+0xf9>
jmp    11da <main+0x8a>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2df8(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1230 <main+0xe0>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jne    121c <main+0xcc>
mov    -0x6(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    122b <main+0xdb>
mov    -0x5(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    11da <main+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e4 <main+0x94>
mov    %rax,%rbx
lea    0xea5(%rip),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e4 <main+0x94>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e4c(%rip),%r15
cmp    (%r15),%al
je     11d0 <main+0x80>
mov    $0x6f,%ebp
cs nopw 0x0(%rax,%rax,1)
cmp    $0x30,%al
movzbl %al,%eax
cmove  %ebp,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11b0 <main+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11f5 <main+0xa5>
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"greski.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"I can't open it!\00"
@.str.3 = [15 x i8] c"greski_out.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store i8 111, i8* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %41
10: ; preds = %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %41
15: ; preds = %10
br label %16
16: ; preds = %35, %15
%17 = load i32*, i32** %4
%18 = call signext i8 @fgetc(i32* %17)
store i8 %18, i8* %2
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %36
23: ; preds = %16
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 48
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8, i8* %3
%29 = load i32*, i32** %5
%30 = call i32 @fputc(i8 signext %28, i32* %29)
br label %35
31: ; preds = %23
%32 = load i8, i8* %2
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i8 signext %32, i32* %33)
br label %35
35: ; preds = %31, %27
br label %16
36: ; preds = %16
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %1
br label %41
41: ; preds = %36, %13, %8
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [11 x i8] c"greski.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"I can't open it!\00"
@.str.3 = [15 x i8] c"greski_out.txt\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call signext i8 @fgetc(i32* %1)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %22, label %14
12: ; preds = %5
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
14: ; preds = %8, %14
%15 = phi i8 [ %19, %14 ], [ %9, %8 ]
%16 = icmp eq i8 %15, 48
%17 = select i1 %16, i8 111, i8 %15
%18 = tail call i32 @fputc(i8 signext %17, i32* %6)
%19 = tail call signext i8 @fgetc(i32* %1)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %22, label %14
22: ; preds = %14, %8
%23 = tail call i32 @fclose(i32* %1)
%24 = tail call i32 @fclose(i32* %6)
br label %25
25: ; preds = %22, %12, %3
%26 = phi i32 [ -1, %3 ], [ -1, %12 ], [ 0, %22 ]
ret i32 %26
}