#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*/ temp;
struct node15 {
  int dummy;
};

/* Variables and functions */
struct node15 *add_num15(struct node15 *, struct node15 *, char *);
struct node15 *create_list15(struct node15 *, struct node15 *, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
struct node15 *getLowest15(struct node15 *, struct node15 *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void Problem15() {
  int n, i;
  char string[1000], temp[1000] = "";
  struct node15 *head = NULL, *current;
  printf("Problem 15: Given n numbers, the program will print out the sorted "
         "numbers in increasing order.\n");
  printf("Input n: ");
  scanf("%d", &n);
  getchar();
  printf("Input %d numbers (separated by a comma): ", n);
  fgets(string, 1000, stdin);
  string[strlen(string) - 1] = '\0';
  printf("The output is: ");
  for (i = 0; i < strlen(string); i++) {
    for (i; string[i] != ',' && i < strlen(string); i++) {
      strncat(temp, &string[i], 1);
    }
    if (head == NULL) {
      head = create_list15(head, current, temp);
      memset(temp, 0, sizeof(temp));
    } else {
      head = add_num15(head, current, temp);
      memset(temp, 0, sizeof(temp));
    }
  }
  while (head) {
    current = head;
    head = getLowest15(head, current);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<Problem15>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
lea    -0x7e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1060 <memset@plt>
movq   $0x0,-0x7e8(%rbp)
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    -0x4(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x3f0(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1080 <fgets@plt>
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x7f4(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x7f4(%rbp),%eax
cmp    %ecx,%eax
jge    138d <Problem15+0x1ed>
movslq -0x8(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x2c,%ecx
mov    %al,-0x7f5(%rbp)
je     12bf <Problem15+0x11f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7fc(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x7fc(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x7f5(%rbp)
mov    -0x7f5(%rbp),%al
test   $0x1,%al
jne    12d2 <Problem15+0x132>
jmp    12ff <Problem15+0x15f>
lea    -0x7e0(%rbp),%rdi
movslq -0x8(%rbp),%rax
lea    -0x3f0(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1070 <strncat@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    127a <Problem15+0xda>
cmpq   $0x0,-0x7e8(%rbp)
jne    1346 <Problem15+0x1a6>
mov    -0x7e8(%rbp),%rdi
mov    -0x7f0(%rbp),%rsi
lea    -0x7e0(%rbp),%rdx
call   10c0 <create_list15@plt>
mov    %rax,-0x7e8(%rbp)
lea    -0x7e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1060 <memset@plt>
jmp    137a <Problem15+0x1da>
mov    -0x7e8(%rbp),%rdi
mov    -0x7f0(%rbp),%rsi
lea    -0x7e0(%rbp),%rdx
call   1030 <add_num15@plt>
mov    %rax,-0x7e8(%rbp)
lea    -0x7e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1060 <memset@plt>
jmp    137f <Problem15+0x1df>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1255 <Problem15+0xb5>
jmp    1392 <Problem15+0x1f2>
cmpq   $0x0,-0x7e8(%rbp)
je     13cd <Problem15+0x22d>
mov    -0x7e8(%rbp),%rax
mov    %rax,-0x7f0(%rbp)
mov    -0x7e8(%rbp),%rdi
mov    -0x7f0(%rbp),%rsi
call   10a0 <getLowest15@plt>
mov    %rax,-0x7e8(%rbp)
jmp    1392 <Problem15+0x1f2>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem15>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f0,%rsp
lea    0x400(%rsp),%rdi
xor    %r13d,%r13d
mov    $0x3e8,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe59(%rip),%rdi
call   1050 <puts@plt>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe02(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10d0 <scanf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    0xc(%rsp),%esi
lea    0xde9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
call   10a0 <fgets@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1343 <Problem15+0x183>
lea    0x400(%rsp),%r14
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
jmp    12c6 <Problem15+0x106>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%r13
test   %r12,%r12
je     1310 <Problem15+0x150>
mov    %r12,%rdi
mov    %r14,%rdx
call   1030 <add_num15@plt>
mov    %rax,%r12
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
add    $0x1,%r13d
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    %eax,%r13d
jge    131c <Problem15+0x15c>
movslq %r13d,%rbx
cmpb   $0x2c,0x10(%rsp,%rbx,1)
je     1293 <Problem15+0xd3>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1290 <Problem15+0xd0>
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1090 <strncat@plt>
lea    0x1(%rbx),%r13
cmpb   $0x2c,0x11(%rsp,%rbx,1)
mov    %r13,%rbx
jne    12d0 <Problem15+0x110>
jmp    1293 <Problem15+0xd3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %r14,%rdx
call   10e0 <create_list15@plt>
jmp    12a3 <Problem15+0xe3>
test   %r12,%r12
je     1343 <Problem15+0x183>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r12,%rsi
call   10c0 <getLowest15@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1330 <Problem15+0x170>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x7f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.node15 = type { i32 }
@.str = [97 x i8] c"Problem 15: Given n numbers, the program will print out the sorted numbers in increasing order.\0A\00"
@.str.1 = [10 x i8] c"Input n: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [42 x i8] c"Input %d numbers (separated by a comma): \00"
@stdin = global i32 0
@.str.4 = [16 x i8] c"The output is: \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @Problem15() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = alloca %struct.node15*
%6 = alloca %struct.node15*
%7 = bitcast [1000 x i8]* %4 to i8*
store %struct.node15* null, %struct.node15** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%11 = call i32 (...) @getchar()
%12 = load i32, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 1000, i32 %15)
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %23
23: ; preds = %71, %0
%24 = load i32, i32* %2
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %74
28: ; preds = %23
%29 = load i32, i32* %2
br label %30
30: ; preds = %50, %28
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 44
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* %2
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = icmp slt i32 %38, %40
br label %42
42: ; preds = %37, %30
%43 = phi i1 [ false, %30 ], [ %41, %37 ]
br i1 %43, label %44, label %53
44: ; preds = %42
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %47
%49 = call i32 @strncat(i8* %45, i8* %48, i32 1)
br label %50
50: ; preds = %44
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %30
53: ; preds = %42
%54 = load %struct.node15*, %struct.node15** %5
%55 = icmp eq %struct.node15* %54, null
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = load %struct.node15*, %struct.node15** %5
%58 = load %struct.node15*, %struct.node15** %6
%59 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%60 = call %struct.node15* @create_list15(%struct.node15* %57, %struct.node15* %58, i8* %59)
store %struct.node15* %60, %struct.node15** %5
%61 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%62 = call i32 @memset(i8* %61, i32 0, i32 1000)
br label %70
63: ; preds = %53
%64 = load %struct.node15*, %struct.node15** %5
%65 = load %struct.node15*, %struct.node15** %6
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%67 = call %struct.node15* @add_num15(%struct.node15* %64, %struct.node15* %65, i8* %66)
store %struct.node15* %67, %struct.node15** %5
%68 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%69 = call i32 @memset(i8* %68, i32 0, i32 1000)
br label %70
70: ; preds = %63, %56
br label %71
71: ; preds = %70
%72 = load i32, i32* %2
%73 = add nsw i32 %72, 1
store i32 %73, i32* %2
br label %23
74: ; preds = %23
br label %75
75: ; preds = %78, %74
%76 = load %struct.node15*, %struct.node15** %5
%77 = icmp ne %struct.node15* %76, null
br i1 %77, label %78, label %83
78: ; preds = %75
%79 = load %struct.node15*, %struct.node15** %5
store %struct.node15* %79, %struct.node15** %6
%80 = load %struct.node15*, %struct.node15** %5
%81 = load %struct.node15*, %struct.node15** %6
%82 = call %struct.node15* @getLowest15(%struct.node15* %80, %struct.node15* %81)
store %struct.node15* %82, %struct.node15** %5
br label %75
83: ; preds = %75
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.node15 = type { i32 }
@.str.1 = [10 x i8] c"Input n: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [42 x i8] c"Input %d numbers (separated by a comma): \00"
@stdin = global i32 0
@.str.4 = [16 x i8] c"The output is: \00"
@str = [96 x i8] c"Problem 15: Given n numbers, the program will print out the sorted numbers in increasing order.\00"
define void @Problem15() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = call i32 (...) @getchar()
%11 = load i32, i32* %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %5, i32 1000, i32 %13)
%15 = call i32 @strlen(i8* %5)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @strlen(i8* %5)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %63
22: ; preds = %0, %53
%23 = phi %struct.node15* [ %54, %53 ], [ null, %0 ]
%24 = phi i32 [ %56, %53 ], [ 0, %0 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 44
br i1 %28, label %46, label %31
29: ; preds = %53
%30 = icmp eq %struct.node15* %54, null
br i1 %30, label %63, label %59
31: ; preds = %22, %37
%32 = phi i64 [ %39, %37 ], [ %25, %22 ]
%33 = phi i8* [ %40, %37 ], [ %26, %22 ]
%34 = call i32 @strlen(i8* %5)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %32, %35
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = call i32 @strncat(i8* %6, i8* %33, i32 1)
%39 = add nsw i64 %32, 1
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 44
br i1 %42, label %43, label %31
43: ; preds = %37, %31
%44 = phi i64 [ %32, %31 ], [ %39, %37 ]
%45 = trunc i64 %44 to i32
br label %46
46: ; preds = %43, %22
%47 = phi i32 [ %24, %22 ], [ %45, %43 ]
%48 = icmp eq %struct.node15* %23, null
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call %struct.node15* @create_list15(%struct.node15* null, %struct.node15* undef, i8* %6)
br label %53
51: ; preds = %46
%52 = call %struct.node15* @add_num15(%struct.node15* %23, %struct.node15* undef, i8* %6)
br label %53
53: ; preds = %49, %51
%54 = phi %struct.node15* [ %50, %49 ], [ %52, %51 ]
%55 = call i32 @memset(i8* %6, i32 0, i32 1000)
%56 = add nsw i32 %47, 1
%57 = call i32 @strlen(i8* %5)
%58 = icmp slt i32 %56, %57
br i1 %58, label %22, label %29
59: ; preds = %29, %59
%60 = phi %struct.node15* [ %61, %59 ], [ %54, %29 ]
%61 = call %struct.node15* @getLowest15(%struct.node15* %60, %struct.node15* %60)
%62 = icmp eq %struct.node15* %61, null
br i1 %62, label %63, label %59
63: ; preds = %59, %0, %29
%64 = call i32 @putchar(i32 10)
ret void
}