#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
char getchar();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  char str[20], c;
  FILE *fp;
  fp = fopen("result", "w");
  printf("input strings:\n");
  gets(str);
  fprintf(fp, "%s ", str);
  c = getchar();
  fclose(fp);
  fp = fopen("result", "r");
  while (fscanf(fp, "%s", str) != EOF) {
    for (i = 0; str[i] != '\0'; i++)
      if ((str[i] >= 'a') && (str[i] <= 'z'))
        str[i] = str[i] - 32;
    printf("%s\n", str);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <gets@plt>
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x21(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe25(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xe25(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%rax
je     128c <main+0x11c>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1275 <main+0x105>
movslq -0x8(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x61,%eax
jl     1262 <main+0xf2>
movslq -0x8(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x7a,%eax
jg     1262 <main+0xf2>
movslq -0x8(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
sub    $0x20,%eax
mov    %al,%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
jmp    1267 <main+0xf7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1216 <main+0xa6>
lea    -0x20(%rbp),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11eb <main+0x7b>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe7c(%rip),%r14
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r15
mov    %r15,%rdi
call   1080 <gets@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe38(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe28(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    0x2def(%rip),%r12
cmp    (%r12),%rax
jne    1217 <main+0xa7>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0x1(%rsp),%r13
mov    %rsp,%rbx
lea    0xde9(%rip),%r15
jmp    124c <main+0xdc>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    (%r12),%rax
je     11ff <main+0x8f>
mov    (%rsp),%al
test   %al,%al
je     1230 <main+0xc0>
mov    %r13,%rcx
jmp    126b <main+0xfb>
nopl   0x0(%rax,%rax,1)
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
je     1230 <main+0xc0>
lea    -0x61(%rax),%edx
cmp    $0x19,%dl
ja     1260 <main+0xf0>
add    $0xe0,%al
mov    %al,-0x1(%rcx)
jmp    1260 <main+0xf0>

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

LLVM IR (-O2):
@.str = [7 x i8] c"result\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
@EOF = global i64 0
@str = [15 x i8] c"input strings:\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%5 = call i32 @gets(i8* %2)
%6 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%7 = call signext i8 (...) @getchar()
%8 = call i32 @fclose(i32* %3)
%9 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%10 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %34, label %13
13: ; preds = %0, %29
%14 = load i8, i8* %2
%15 = icmp eq i8 %14, 0
br i1 %15, label %29, label %16
16: ; preds = %13, %24
%17 = phi i64 [ %25, %24 ], [ 0, %13 ]
%18 = phi i8 [ %27, %24 ], [ %14, %13 ]
%19 = phi i8* [ %26, %24 ], [ %2, %13 ]
%20 = add i8 %18, -97
%21 = icmp ult i8 %20, 26
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = add nsw i8 %18, -32
store i8 %23, i8* %19
br label %24
24: ; preds = %16, %22
%25 = add nuw i64 %17, 1
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %16
29: ; preds = %24, %13
%30 = call i32 @puts(i8* %2)
%31 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %13
34: ; preds = %29, %0
%35 = call i32 @fclose(i32* %9)
ret i32 0
}