#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int main() {
  FILE *fp;
  char str[100];
  int i = 0;
  if ((fp = fopen("file", "w")) == NULL) {
    printf("can not open file\n");
    exit(0);
  }
  printf("input a string :\n");
  gets(str);
  while (str[i] != '!') {
    if (str[i] >= 'a' && str[i] <= 'z')
      str[i] = str[i] - 32;
    fputc(str[i], fp);
    i++;
  }
  fclose(fp);
  fp = fopen("file", "r");
  fgets(str, strlen(str) + 1, fp);
  printf("%s\n", str);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x84(%rbp)
lea    0xe5d(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d2 <main+0x52>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1080 <gets@plt>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x21,%eax
je     126f <main+0xef>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x61,%eax
jl     1244 <main+0xc4>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x7a,%eax
jg     1244 <main+0xc4>
movslq -0x84(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
sub    $0x20,%eax
mov    %al,%cl
movslq -0x84(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11e9 <main+0x69>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd81(%rip),%rdi
lea    0xda6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rdx
call   1070 <fgets@plt>
lea    -0x80(%rbp),%rsi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe94(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1245 <main+0xc5>
mov    %rax,%r14
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1080 <gets@plt>
mov    (%rsp),%al
cmp    $0x21,%al
jne    1213 <main+0x93>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe52(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0x1(%rsp),%rbx
jmp    1236 <main+0xb6>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
cmp    $0x21,%al
je     11c1 <main+0x41>
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
ja     1220 <main+0xa0>
add    $0xe0,%al
mov    %al,-0x1(%rbx)
jmp    1220 <main+0xa0>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"can not open file\0A\00"
@.str.3 = [18 x i8] c"input a string :\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 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 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @gets(i8* %12)
br label %14
14: ; preds = %46, %10
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 33
br i1 %20, label %21, label %55
21: ; preds = %14
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sge i32 %26, 97
br i1 %27, label %28, label %46
28: ; preds = %21
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 122
br i1 %34, label %35, label %46
35: ; preds = %28
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 32
%42 = trunc i32 %41 to i8
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %35, %28, %21
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i32*, i32** %2
%52 = call i32 @fputc(i8 signext %50, i32* %51)
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %14
55: ; preds = %14
%56 = load i32*, i32** %2
%57 = call i32 @fclose(i32* %56)
%58 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %58, i32** %2
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%61 = call i64 @strlen(i8* %60)
%62 = add nsw i64 %61, 1
%63 = load i32*, i32** %2
%64 = call i32 @fgets(i8* %59, i64 %62, i32* %63)
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %65)
%67 = load i32*, i32** %2
%68 = call i32 @fclose(i32* %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.4 = [2 x i8] c"r\00"
@str = [17 x i8] c"input a string :\00"
@str.6 = [18 x i8] c"can not open file\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 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 %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%10 = call i32 @gets(i8* %2)
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 33
br i1 %12, label %28, label %13
13: ; preds = %8, %21
%14 = phi i64 [ %24, %21 ], [ 0, %8 ]
%15 = phi i8 [ %26, %21 ], [ %11, %8 ]
%16 = phi i8* [ %25, %21 ], [ %2, %8 ]
%17 = add i8 %15, -97
%18 = icmp ult i8 %17, 26
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = add nsw i8 %15, -32
store i8 %20, i8* %16
br label %21
21: ; preds = %19, %13
%22 = phi i8 [ %20, %19 ], [ %15, %13 ]
%23 = call i32 @fputc(i8 signext %22, i32* %3)
%24 = add nuw i64 %14, 1
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 33
br i1 %27, label %28, label %13
28: ; preds = %21, %8
%29 = call i32 @fclose(i32* %3)
%30 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i64 @strlen(i8* %2)
%32 = add nsw i64 %31, 1
%33 = call i32 @fgets(i8* %2, i64 %32, i32* %30)
%34 = call i32 @puts(i8* %2)
%35 = call i32 @fclose(i32* %30)
ret i32 0
}