#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  int c;
  char buffer[256];
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error in opening file");
    return (-1);
  }
  while (!feof(fp)) {
    c = getc(fp);
    if (c == '!')
      ungetc('+', fp);
    else
      ungetc(c, fp);
    fgets(buffer, 255, fp);
    fputs(buffer, stdout);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bc <main+0x4c>
lea    0xe60(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <main+0xda>
jmp    11c1 <main+0x51>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11df <main+0x6f>
jmp    1243 <main+0xd3>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x21,-0x14(%rbp)
jne    1208 <main+0x98>
mov    -0x10(%rbp),%rsi
mov    $0x2b,%edi
call   1060 <ungetc@plt>
jmp    1214 <main+0xa4>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ungetc@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
lea    -0x120(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    11c1 <main+0x51>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xe7a(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1214 <main+0xa4>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    1201 <main+0x91>
mov    $0x2b,%r15d
mov    %rsp,%rbp
mov    0x2e27(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    $0x21,%eax
cmove  %r15d,%eax
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    (%r12),%esi
mov    %rbp,%rdi
call   1030 <fputs@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11c0 <main+0x50>
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1201 <main+0x91>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error in opening file\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %36
10: ; preds = %0
br label %11
11: ; preds = %28, %10
%12 = load i32*, i32** %2
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = load i32*, i32** %2
%18 = call i32 @getc(i32* %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 33
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32*, i32** %2
%23 = call i32 @ungetc(i32 43, i32* %22)
br label %28
24: ; preds = %16
%25 = load i32, i32* %3
%26 = load i32*, i32** %2
%27 = call i32 @ungetc(i32 %25, i32* %26)
br label %28
28: ; preds = %24, %21
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%30 = load i32*, i32** %2
%31 = call i32 @fgets(i8* %29, i32 255, i32* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%33 = load i32, i32* @stdout
%34 = call i32 @fputs(i8* %32, i32 %33)
br label %11
35: ; preds = %11
store i32 0, i32* %1
br label %36
36: ; preds = %35, %8
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error in opening file\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %20
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %20
10: ; preds = %5, %10
%11 = call i32 @getc(i32* %3)
%12 = icmp eq i32 %11, 33
%13 = select i1 %12, i32 43, i32 %11
%14 = call i32 @ungetc(i32 %13, i32* %3)
%15 = call i32 @fgets(i8* %2, i32 255, i32* %3)
%16 = load i32, i32* @stdout
%17 = call i32 @fputs(i8* %2, i32 %16)
%18 = call i32 @feof(i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %10, label %20
20: ; preds = %10, %5, %8
%21 = phi i32 [ -1, %8 ], [ 0, %5 ], [ 0, %10 ]
ret i32 %21
}