#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ vis5d_get_context_name(int, char *);
int /*<<< orphan*/ vis5d_get_itx_name(int, char *);
int /*<<< orphan*/ vis5d_get_num_of_ctxs_in_display(int, int *, int *);
int /*<<< orphan*/ vis5d_get_num_of_itxs_in_display(int, int *, int *);
char **read_ctx(int *count, int display) {
  char **entries;
  int i;
  int yo;
  int othercount;
  int whichones[20];
  entries = (char **)malloc(100 * sizeof(char *));
  vis5d_get_num_of_ctxs_in_display(display, &yo, whichones);
  othercount = 0;
  for (i = 0; i < yo; i++) {
    char str[1000], str2[1000], str3[1000];
    strcpy(str, "Context-");
    sprintf(str2, "%d", whichones[i]);
    strcat(str, str2);
    strcat(str, "  ");
    vis5d_get_context_name(whichones[i], str3);
    strcat(str, str3);
    entries[othercount] = strdup(str);
    othercount++;
  }
  vis5d_get_num_of_itxs_in_display(display, &yo, whichones);
  for (i = 0; i < yo; i++) {
    char str[1000], str2[1000], str3[1000];
    strcpy(str, "I_Context-");
    sprintf(str2, "%d", whichones[i]);
    strcat(str, str2);
    strcat(str, "  ");
    vis5d_get_itx_name(whichones[i], str3);
    strcat(str, str3);
    entries[othercount] = strdup(str);
    othercount++;
  }
  *count = othercount;
  return entries;
}


x86 assembly (clang, -O0):
<read_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x320,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1030 <vis5d_get_num_of_ctxs_in_display@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1287 <read_ctx+0xf7>
lea    -0x470(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x860(%rbp),%rdi
movslq -0x1c(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%edx
lea    0xdfd(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x470(%rbp),%rdi
lea    -0x860(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x470(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1090 <strcat@plt>
movslq -0x1c(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%edi
lea    -0xc50(%rbp),%rsi
call   1050 <vis5d_get_context_name@plt>
lea    -0x470(%rbp),%rdi
lea    -0xc50(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x470(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <read_ctx+0x3e>
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1070 <vis5d_get_num_of_itxs_in_display@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1357 <read_ctx+0x1c7>
lea    -0x1040(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x1430(%rbp),%rdi
movslq -0x1c(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%edx
lea    0xd2d(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x1040(%rbp),%rdi
lea    -0x1430(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x1040(%rbp),%rdi
lea    0xd0a(%rip),%rsi
call   1090 <strcat@plt>
movslq -0x1c(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%edi
lea    -0x1820(%rbp),%rsi
call   1060 <vis5d_get_itx_name@plt>
lea    -0x1040(%rbp),%rdi
lea    -0x1820(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x1040(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    129e <read_ctx+0x10e>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ctx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc38,%rsp
mov    %esi,%ebp
mov    %rdi,0x18(%rsp)
mov    $0x320,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   1030 <vis5d_get_num_of_ctxs_in_display@plt>
cmpl   $0x0,0xc(%rsp)
jle    1275 <read_ctx+0xe5>
mov    %ebp,0x10(%rsp)
xor    %r15d,%r15d
mov    %rbx,%rbp
lea    0x850(%rsp),%rbx
lea    0x460(%rsp),%r14
lea    0xe11(%rip),%r13
lea    0x70(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xdfe(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x20(%rsp,%r15,4),%edx
mov    %r14,%rdi
lea    0xde2(%rip),%rsi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
mov    0x20(%rsp,%r15,4),%edi
mov    %r12,%rsi
call   1050 <vis5d_get_context_name@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   10b0 <strdup@plt>
mov    %rax,0x0(%rbp,%r15,8)
add    $0x1,%r15
movslq 0xc(%rsp),%rax
cmp    %rax,%r15
jl     1200 <read_ctx+0x70>
mov    %rbp,%rbx
mov    0x10(%rsp),%ebp
jmp    1278 <read_ctx+0xe8>
xor    %r15d,%r15d
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   1070 <vis5d_get_num_of_itxs_in_display@plt>
cmpl   $0x0,0xc(%rsp)
jle    1338 <read_ctx+0x1a8>
mov    %r15d,%r15d
mov    %rbx,0x10(%rsp)
lea    (%rbx,%r15,8),%r13
xor    %r14d,%r14d
lea    0x850(%rsp),%rbx
lea    0x460(%rsp),%r12
lea    0x70(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xd3c(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x20(%rsp,%r14,4),%edx
mov    %r12,%rdi
lea    0xd22(%rip),%rsi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
lea    0xd0b(%rip),%rsi
call   1090 <strcat@plt>
mov    0x20(%rsp,%r14,4),%edi
mov    %rbp,%rsi
call   1060 <vis5d_get_itx_name@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   10b0 <strdup@plt>
mov    %rax,0x0(%r13,%r14,8)
add    $0x1,%r14
movslq 0xc(%rsp),%rax
cmp    %rax,%r14
jl     12c0 <read_ctx+0x130>
add    %r14d,%r15d
mov    0x10(%rsp),%rbx
mov    0x18(%rsp),%rax
mov    %r15d,(%rax)
mov    %rbx,%rax
add    $0xc38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"Context-\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [11 x i8] c"I_Context-\00"
define i8** @read_ctx(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = alloca [20 x i32]
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i8]
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca [1000 x i8]
%11 = bitcast i32* %3 to i8*
%12 = bitcast [20 x i32]* %4 to i8*
%13 = tail call i64 @malloc(i32 800)
%14 = inttoptr i64 %13 to i8**
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%16 = call i32 @vis5d_get_num_of_ctxs_in_display(i32 %1, i32* %3, i32* %15)
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %42
19: ; preds = %2
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
br label %23
23: ; preds = %19, %23
%24 = phi i64 [ 0, %19 ], [ %36, %23 ]
%25 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%26 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %24
%27 = load i32, i32* %26
%28 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @strcat(i8* %20, i8* %21)
%30 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %26
%32 = call i32 @vis5d_get_context_name(i32 %31, i8* %22)
%33 = call i32 @strcat(i8* %20, i8* %22)
%34 = call i8* @strdup(i8* %20)
%35 = getelementptr inbounds i8*, i8** %14, i64 %24
store i8* %34, i8** %35
%36 = add nuw nsw i64 %24, 1
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %23, label %40
40: ; preds = %23
%41 = trunc i64 %36 to i32
br label %42
42: ; preds = %40, %2
%43 = phi i32 [ 0, %2 ], [ %41, %40 ]
%44 = call i32 @vis5d_get_num_of_itxs_in_display(i32 %1, i32* %3, i32* %15)
%45 = load i32, i32* %3
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %73
47: ; preds = %42
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%51 = zext i32 %43 to i64
br label %52
52: ; preds = %47, %52
%53 = phi i64 [ 0, %47 ], [ %67, %52 ]
%54 = phi i64 [ %51, %47 ], [ %66, %52 ]
%55 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%56 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %53
%57 = load i32, i32* %56
%58 = call i32 @sprintf(i8* %49, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = call i32 @strcat(i8* %48, i8* %49)
%60 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* %56
%62 = call i32 @vis5d_get_itx_name(i32 %61, i8* %50)
%63 = call i32 @strcat(i8* %48, i8* %50)
%64 = call i8* @strdup(i8* %48)
%65 = getelementptr inbounds i8*, i8** %14, i64 %54
store i8* %64, i8** %65
%66 = add nuw nsw i64 %54, 1
%67 = add nuw nsw i64 %53, 1
%68 = load i32, i32* %3
%69 = sext i32 %68 to i64
%70 = icmp slt i64 %67, %69
br i1 %70, label %52, label %71
71: ; preds = %52
%72 = trunc i64 %66 to i32
br label %73
73: ; preds = %71, %42
%74 = phi i32 [ %43, %42 ], [ %72, %71 ]
store i32 %74, i32* %0
ret i8** %14
}