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


x86 assembly (clang, -O0):
<ugetc_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ae <ugetc_t+0x3e>
lea    0xe67(%rip),%rdi
call   1080 <perror@plt>
jmp    1235 <ugetc_t+0xc5>
jmp    11b3 <ugetc_t+0x43>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d1 <ugetc_t+0x61>
jmp    1235 <ugetc_t+0xc5>
mov    -0x8(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x21,-0xc(%rbp)
jne    11fa <ugetc_t+0x8a>
mov    -0x8(%rbp),%rsi
mov    $0x2b,%edi
call   1060 <ungetc@plt>
jmp    1206 <ugetc_t+0x96>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1060 <ungetc@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    11b3 <ugetc_t+0x43>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ugetc_t>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe7c(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <ugetc_t+0x9e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1200 <ugetc_t+0x90>
mov    $0x2b,%r15d
mov    %rsp,%r14
mov    0x2e2c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    $0x21,%eax
cmove  %r15d,%eax
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
mov    %r14,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1030 <fputs@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11c0 <ugetc_t+0x50>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf6(%rip),%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <perror@plt>

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 void @ugetc_t() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = 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* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %34
9: ; preds = %0
br label %10
10: ; preds = %27, %9
%11 = load i32*, i32** %1
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %34
15: ; preds = %10
%16 = load i32*, i32** %1
%17 = call i32 @getc(i32* %16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 33
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32*, i32** %1
%22 = call i32 @ungetc(i32 43, i32* %21)
br label %27
23: ; preds = %15
%24 = load i32, i32* %2
%25 = load i32*, i32** %1
%26 = call i32 @ungetc(i32 %24, i32* %25)
br label %27
27: ; preds = %23, %20
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = load i32*, i32** %1
%30 = call i32 @fgets(i8* %28, i32 255, i32* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = load i32, i32* @stdout
%33 = call i32 @fputs(i8* %31, i32 %32)
br label %10
34: ; preds = %7, %10
ret void
}

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 void @ugetc_t() {
%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
ret void
}