#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  FILE *fp;
  char str[3][10], temp[10];
  int i, j, k;
  int n = 3;
  printf("Enter strings:\n");
  for (i = 0; i < n; i++)
    gets(str[i]);
  for (i = 0; i < n - 1; i++) {
    k = i;
    for (j = i + 1; j < n; j++) {
      if (strcmp(str[k], str[j]) > 0)
        k = j;
    }
    if (k != i) {
      strcpy(temp, str[i]);
      strcpy(str[i], str[k]);
      strcpy(str[k], temp);
    }
  }
  if ((fp = fopen("/Users/chen/file", "w")) == NULL) {
    printf("can't open file!\n");
    exit(0);
  }
  printf("The new sequence :\n");
  for (i = 0; i < n; i++) {
    fputs(str[i], fp);
    fputs("\n", fp);
    printf("%s\n", str[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x4c(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    11c9 <main+0x59>
movslq -0x40(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
call   1070 <gets@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    119b <main+0x2b>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b4 <main+0x144>
mov    -0x40(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1242 <main+0xd2>
movslq -0x48(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xa,%rax,%rax
add    %rax,%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jle    122f <main+0xbf>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    1234 <main+0xc4>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f0 <main+0x80>
mov    -0x48(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     12a1 <main+0x131>
lea    -0x3a(%rbp),%rdi
movslq -0x40(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xa,%rax,%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
movslq -0x40(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
movslq -0x48(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xa,%rax,%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
movslq -0x48(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
lea    -0x3a(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12a6 <main+0x136>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11d0 <main+0x60>
lea    0xd55(%rip),%rdi
lea    0xd5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12ea <main+0x17a>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    135e <main+0x1ee>
movslq -0x40(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xd05(%rip),%rdi
call   1050 <fputs@plt>
movslq -0x40(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xa,%rax,%rax
add    %rax,%rsi
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12ff <main+0x18f>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
lea    0xa(%rsp),%r15
mov    %r15,%rdi
call   1080 <gets@plt>
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1080 <gets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
xor    %r12d,%r12d
test   %rax,%rax
setg   %r12b
lea    (%r12,%r12,1),%rax
lea    (%rax,%rax,4),%rdi
or     %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    $0x2,%ebx
cmovle %r12,%rbx
test   %rbx,%rbx
je     1228 <main+0xa8>
lea    0x26(%rsp),%r12
mov    %rsp,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    (%rbx,%rbx,4),%rax
lea    (%rsp,%rax,2),%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jle    1263 <main+0xe3>
lea    0x26(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0x14(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xd96(%rip),%rdi
lea    0xda0(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1301 <main+0x181>
mov    %rax,%rbx
lea    0xd99(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd2d(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Enter strings:\0A\00"
@.str.1 = [17 x i8] c"/Users/chen/file\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [18 x i8] c"can't open file!\0A\00"
@.str.4 = [20 x i8] c"The new sequence :\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [3 x [10 x i8]]
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %5
%12 = load i32, i32* %8
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %16
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %17, i64 0, i64 0
%19 = call i32 @gets(i8* %18)
br label %20
20: ; preds = %14
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %10
23: ; preds = %10
store i32 0, i32* %5
br label %24
24: ; preds = %81, %23
%25 = load i32, i32* %5
%26 = load i32, i32* %8
%27 = sub nsw i32 %26, 1
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %84
29: ; preds = %24
%30 = load i32, i32* %5
store i32 %30, i32* %7
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %33
33: ; preds = %51, %29
%34 = load i32, i32* %6
%35 = load i32, i32* %8
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %54
37: ; preds = %33
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %39
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %40, i64 0, i64 0
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %43
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %44, i64 0, i64 0
%46 = call i64 @strcmp(i8* %41, i8* %45)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %37
%49 = load i32, i32* %6
store i32 %49, i32* %7
br label %50
50: ; preds = %48, %37
br label %51
51: ; preds = %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %33
54: ; preds = %33
%55 = load i32, i32* %7
%56 = load i32, i32* %5
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %80
58: ; preds = %54
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %61
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %62, i64 0, i64 0
%64 = call i32 @strcpy(i8* %59, i8* %63)
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %66
%68 = getelementptr inbounds [10 x i8], [10 x i8]* %67, i64 0, i64 0
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %70
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %71, i64 0, i64 0
%73 = call i32 @strcpy(i8* %68, i8* %72)
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %75
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %76, i64 0, i64 0
%78 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%79 = call i32 @strcpy(i8* %77, i8* %78)
br label %80
80: ; preds = %58, %54
br label %81
81: ; preds = %80
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 1
store i32 %83, i32* %5
br label %24
84: ; preds = %24
%85 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %85, i32** %2
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%89 = call i32 @exit(i32 0)
unreachable
90: ; preds = %84
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %92
92: ; preds = %110, %90
%93 = load i32, i32* %5
%94 = load i32, i32* %8
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %113
96: ; preds = %92
%97 = load i32, i32* %5
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %98
%100 = getelementptr inbounds [10 x i8], [10 x i8]* %99, i64 0, i64 0
%101 = load i32*, i32** %2
%102 = call i32 @fputs(i8* %100, i32* %101)
%103 = load i32*, i32** %2
%104 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* %103)
%105 = load i32, i32* %5
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %106
%108 = getelementptr inbounds [10 x i8], [10 x i8]* %107, i64 0, i64 0
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %108)
br label %110
110: ; preds = %96
%111 = load i32, i32* %5
%112 = add nsw i32 %111, 1
store i32 %112, i32* %5
br label %92
113: ; preds = %92
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"/Users/chen/file\00"
@.str.2 = [2 x i8] c"w\00"
@str = [15 x i8] c"Enter strings:\00"
@str.7 = [19 x i8] c"The new sequence :\00"
@str.8 = [17 x i8] c"can't open file!\00"
define i32 @main() {
%1 = alloca [3 x [10 x i8]]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
%7 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 1, i64 0
%8 = call i32 @gets(i8* %7)
%9 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 2, i64 0
%10 = call i32 @gets(i8* %9)
%11 = call i64 @strcmp(i8* %3, i8* %7)
%12 = icmp sgt i64 %11, 0
%13 = zext i1 %12 to i64
%14 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 %13, i64 0
%15 = call i64 @strcmp(i8* %14, i8* %9)
%16 = icmp sgt i64 %15, 0
%17 = zext i1 %12 to i64
%18 = select i1 %16, i64 2, i64 %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %0
%21 = call i32 @strcpy(i8* %4, i8* %3)
%22 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 %18, i64 0
%23 = call i32 @strcpy(i8* %3, i8* %22)
%24 = call i32 @strcpy(i8* %22, i8* %4)
br label %25
25: ; preds = %0, %20
%26 = call i64 @strcmp(i8* %7, i8* %9)
%27 = icmp slt i64 %26, 1
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = call i32 @strcpy(i8* %4, i8* %7)
%30 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 2, i64 0
%31 = call i32 @strcpy(i8* %7, i8* %30)
%32 = call i32 @strcpy(i8* %30, i8* %4)
br label %33
33: ; preds = %28, %25
%34 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %33
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%41 = call i32 @fputs(i8* %3, i32* %34)
%42 = call i32 @fputc(i32 10, i32* %34)
%43 = call i32 @puts(i8* %3)
%44 = call i32 @fputs(i8* %7, i32* %34)
%45 = call i32 @fputc(i32 10, i32* %34)
%46 = call i32 @puts(i8* %7)
%47 = call i32 @fputs(i8* %9, i32* %34)
%48 = call i32 @fputc(i32 10, i32* %34)
%49 = call i32 @puts(i8* %9)
ret i32 0
}