#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 */

/* Variables and functions */
char *malloc(scalar_t__);
int /*<<< orphan*/ print_current_word(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_line(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(void) {
  char *reminders[50];
  char day_str[3], msg_str[60 + 1];
  int i, j, day, num_remind = 0;
  for (;;) {
    if (num_remind == 50) {
      printf("Out of memory!\n");
    }
    printf("enter day and reminder: ");
    scanf("%2d", &day);
    if (day == 0)
      break;
    sprintf(day_str, "%2d", day);
    read_line(msg_str, 60);
    for (i = 0; i < num_remind; i++)
      if (strcmp(day_str, reminders[i]) < 0)
        break;
    for (j = num_remind; j > i; j--)
      reminders[j] = reminders[j - 1];
    reminders[i] = malloc(2 + strlen(msg_str) + 1);
    if (reminders[i] == NULL) {
      printf("ERROR: malloc failed!\n");
      break;
    }
    strcpy(reminders[i], day_str);
    strcat(reminders[i], msg_str);
    num_remind++;
  }
  for (i = 0; i < num_remind; i++) {
    print_current_word(reminders[i], 60);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1f0(%rbp)
cmpl   $0x32,-0x1f0(%rbp)
jne    11d5 <main+0x35>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
lea    0xe41(%rip),%rdi
lea    -0x1ec(%rbp),%rsi
call   1080 <scanf@plt>
cmpl   $0x0,-0x1ec(%rbp)
jne    1206 <main+0x66>
jmp    1382 <main+0x1e2>
lea    -0x1a3(%rbp),%rdi
mov    -0x1ec(%rbp),%edx
lea    0xe0f(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x1e0(%rbp),%rdi
mov    $0x3c,%esi
call   1090 <read_line@plt>
movl   $0x0,-0x1e4(%rbp)
mov    -0x1e4(%rbp),%eax
cmp    -0x1f0(%rbp),%eax
jge    128f <main+0xef>
lea    -0x1a3(%rbp),%rdi
movslq -0x1e4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,8),%rsi
ff
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jge    1276 <main+0xd6>
jmp    128f <main+0xef>
jmp    127b <main+0xdb>
mov    -0x1e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1e4(%rbp)
jmp    123a <main+0x9a>
mov    -0x1f0(%rbp),%eax
mov    %eax,-0x1e8(%rbp)
mov    -0x1e8(%rbp),%eax
cmp    -0x1e4(%rbp),%eax
jle    12e3 <main+0x143>
mov    -0x1e8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1a0(%rbp,%rax,8),%rcx
ff
movslq -0x1e8(%rbp),%rax
mov    %rcx,-0x1a0(%rbp,%rax,8)
ff
mov    -0x1e8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1e8(%rbp)
jmp    129b <main+0xfb>
lea    -0x1e0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
movslq -0x1e4(%rbp),%rax
mov    %rcx,-0x1a0(%rbp,%rax,8)
ff
movslq -0x1e4(%rbp),%rax
cmpq   $0x0,-0x1a0(%rbp,%rax,8)
jne    1338 <main+0x198>
lea    0xcff(%rip),%rdi
call   1050 <printf@plt>
jmp    1382 <main+0x1e2>
movslq -0x1e4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,8),%rdi
ff
lea    -0x1a3(%rbp),%rsi
call   1030 <strcpy@plt>
movslq -0x1e4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,8),%rdi
ff
lea    -0x1e0(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x1f0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f0(%rbp)
jmp    11bc <main+0x1c>
movl   $0x0,-0x1e4(%rbp)
mov    -0x1e4(%rbp),%eax
cmp    -0x1f0(%rbp),%eax
jge    13cb <main+0x22b>
movslq -0x1e4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,8),%rdi
ff
mov    $0x3c,%esi
call   10c0 <print_current_word@plt>
mov    -0x1e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1e4(%rbp)
jmp    138c <main+0x1ec>
xor    %eax,%eax
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1e8,%rsp
xor    %r15d,%r15d
lea    0xe4e(%rip),%r13
lea    0xd(%rsp),%rbx
lea    0x10(%rsp),%r12
cmp    $0x32,%r15
jne    11ec <main+0x3c>
nopl   0x0(%rax,%rax,1)
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0d(%rip),%rdi
call   1060 <printf@plt>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x8(%rsp),%edx
test   %edx,%edx
je     12c9 <main+0x119>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <sprintf@plt>
mov    %r12,%rdi
mov    $0x3c,%esi
call   10a0 <read_line@plt>
xor    %ebp,%ebp
test   %r15,%r15
je     124e <main+0x9e>
mov    0x50(%rsp,%rbp,8),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
js     124e <main+0x9e>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1230 <main+0x80>
mov    %r15,%rbp
mov    %ebp,%ebp
cmp    %rbp,%r15
jbe    1276 <main+0xc6>
movslq %ebp,%rax
mov    %r15,%rcx
nopl   0x0(%rax,%rax,1)
mov    0x48(%rsp,%rcx,8),%rdx
mov    %rdx,0x50(%rsp,%rcx,8)
lea    -0x1(%rcx),%rdx
mov    %rdx,%rcx
cmp    %rax,%rdx
jg     1260 <main+0xb0>
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x3(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,0x50(%rsp,%rbp,8)
test   %rax,%rax
je     12bd <main+0x10d>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
add    $0x1,%r15
cmp    $0x32,%r15
je     11e0 <main+0x30>
jmp    11ec <main+0x3c>
lea    0xd59(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
je     12f8 <main+0x148>
mov    %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x50(%rsp,%rbp,8),%rdi
mov    $0x3c,%esi
call   10d0 <print_current_word@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12e0 <main+0x130>
xor    %eax,%eax
add    $0x1e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Out of memory!\0A\00"
@.str.1 = [25 x i8] c"enter day and reminder: \00"
@.str.2 = [4 x i8] c"%2d\00"
@.str.3 = [23 x i8] c"ERROR: malloc failed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8*]
%3 = alloca [3 x i8]
%4 = alloca [61 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
br label %9
9: ; preds = %77, %0
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, 50
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %92
20: ; preds = %14
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%22 = load i32, i32* %7
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [61 x i8], [61 x i8]* %4, i64 0, i64 0
%25 = call i32 @read_line(i8* %24, i32 60)
store i32 0, i32* %5
br label %26
26: ; preds = %40, %20
%27 = load i32, i32* %5
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %31, i8* %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
br label %43
39: ; preds = %30
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %26
43: ; preds = %38, %26
%44 = load i32, i32* %8
store i32 %44, i32* %6
br label %45
45: ; preds = %58, %43
%46 = load i32, i32* %6
%47 = load i32, i32* %5
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %61
49: ; preds = %45
%50 = load i32, i32* %6
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %56
store i8* %54, i8** %57
br label %58
58: ; preds = %49
%59 = load i32, i32* %6
%60 = add nsw i32 %59, -1
store i32 %60, i32* %6
br label %45
61: ; preds = %45
%62 = getelementptr inbounds [61 x i8], [61 x i8]* %4, i64 0, i64 0
%63 = call i64 @strlen(i8* %62)
%64 = add nsw i64 2, %63
%65 = add nsw i64 %64, 1
%66 = call i8* @malloc(i64 %65)
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %68
store i8* %66, i8** %69
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %71
%73 = load i8*, i8** %72
%74 = icmp eq i8* %73, null
br i1 %74, label %75, label %77
75: ; preds = %61
%76 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %92
77: ; preds = %61
%78 = load i32, i32* %5
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %79
%81 = load i8*, i8** %80
%82 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%83 = call i32 @strcpy(i8* %81, i8* %82)
%84 = load i32, i32* %5
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %85
%87 = load i8*, i8** %86
%88 = getelementptr inbounds [61 x i8], [61 x i8]* %4, i64 0, i64 0
%89 = call i32 @strcat(i8* %87, i8* %88)
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %9
92: ; preds = %75, %19
store i32 0, i32* %5
br label %93
93: ; preds = %103, %92
%94 = load i32, i32* %5
%95 = load i32, i32* %8
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %106
97: ; preds = %93
%98 = load i32, i32* %5
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [50 x i8*], [50 x i8*]* %2, i64 0, i64 %99
%101 = load i8*, i8** %100
%102 = call i32 @print_current_word(i8* %101, i32 60)
br label %103
103: ; preds = %97
%104 = load i32, i32* %5
%105 = add nsw i32 %104, 1
store i32 %105, i32* %5
br label %93
106: ; preds = %93
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"enter day and reminder: \00"
@.str.2 = [4 x i8] c"%2d\00"
@str = [22 x i8] c"ERROR: malloc failed!\00"
@str.4 = [15 x i8] c"Out of memory!\00"
define i32 @main() {
%1 = alloca [50 x i8*]
%2 = alloca [3 x i8]
%3 = alloca [61 x i8]
%4 = alloca i32
%5 = bitcast [50 x i8*]* %1 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
br label %9
9: ; preds = %56, %0
%10 = phi i64 [ %59, %56 ], [ 0, %0 ]
%11 = icmp eq i64 %10, 50
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %60, label %19
19: ; preds = %14
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%21 = call i32 @read_line(i8* %7, i32 60)
%22 = icmp eq i64 %10, 0
br i1 %22, label %35, label %23
23: ; preds = %19, %29
%24 = phi i64 [ %30, %29 ], [ 0, %19 ]
%25 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %6, i8* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %10
br i1 %31, label %32, label %23
32: ; preds = %23, %29
%33 = phi i64 [ %10, %29 ], [ %24, %23 ]
%34 = trunc i64 %33 to i32
br label %35
35: ; preds = %32, %19
%36 = phi i32 [ 0, %19 ], [ %34, %32 ]
%37 = zext i32 %36 to i64
%38 = icmp ugt i64 %10, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = sext i32 %36 to i64
br label %41
41: ; preds = %39, %41
%42 = phi i64 [ %10, %39 ], [ %43, %41 ]
%43 = add nsw i64 %42, -1
%44 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %42
store i8* %45, i8** %46
%47 = icmp sgt i64 %43, %40
br i1 %47, label %41, label %48
48: ; preds = %41, %35
%49 = call i64 @strlen(i8* %7)
%50 = add nsw i64 %49, 3
%51 = call i8* @malloc(i64 %50)
%52 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %37
store i8* %51, i8** %52
%53 = icmp eq i8* %51, null
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %60
56: ; preds = %48
%57 = call i32 @strcpy(i8* %51, i8* %6)
%58 = call i32 @strcat(i8* %51, i8* %7)
%59 = add nuw i64 %10, 1
br label %9
60: ; preds = %14, %54
%61 = trunc i64 %10 to i32
%62 = icmp eq i32 %61, 0
br i1 %62, label %72, label %63
63: ; preds = %60
%64 = and i64 %10, 4294967295
br label %65
65: ; preds = %63, %65
%66 = phi i64 [ 0, %63 ], [ %70, %65 ]
%67 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @print_current_word(i8* %68, i32 60)
%70 = add nuw nsw i64 %66, 1
%71 = icmp eq i64 %70, %64
br i1 %71, label %72, label %65
72: ; preds = %65, %60
ret i32 0
}