#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 fread(char *, int, int, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int readCVec(FILE *fp, int mode, char v[], int dim) {
  int i, k;
  int t;
  if (3 == mode) {
    for (i = 0; i < dim; i++) {
      k = fread(v + i, sizeof(char), 1, fp);
      if (k != 1)
        return 1;
    }
  } else {
    for (i = 0; i < dim; i++) {
      k = fscanf(fp, "%d", &t);
      if (k != 1)
        return 1;
      v[i] = (char)t;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readCVec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    $0x3,%eax
cmp    -0x14(%rbp),%eax
jne    11a3 <readCVec+0x83>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    119e <readCVec+0x7e>
mov    -0x20(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     118b <readCVec+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    120d <readCVec+0xed>
jmp    1190 <readCVec+0x70>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114b <readCVec+0x2b>
jmp    1206 <readCVec+0xe6>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1201 <readCVec+0xe1>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11e3 <readCVec+0xc3>
movl   $0x1,-0x4(%rbp)
jmp    120d <readCVec+0xed>
mov    -0x30(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11aa <readCVec+0x8a>
jmp    1206 <readCVec+0xe6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readCVec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
cmp    $0x3,%esi
jne    1176 <readCVec+0x56>
test   %ecx,%ecx
jle    11b4 <readCVec+0x94>
mov    %ecx,%ebp
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    11bf <readCVec+0x9f>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
jne    1150 <readCVec+0x30>
jmp    11b4 <readCVec+0x94>
test   %ecx,%ecx
jle    11b4 <readCVec+0x94>
mov    %ecx,%r13d
xor    %ebp,%ebp
lea    0xe7a(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b9 <readCVec+0x99>
movzbl 0x4(%rsp),%eax
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1190 <readCVec+0x70>
xor    %r15d,%r15d
jmp    11bf <readCVec+0x9f>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @readCVec(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i32, i32* %7
%14 = icmp eq i32 3, %13
br i1 %14, label %15, label %35
15: ; preds = %4
store i32 0, i32* %10
br label %16
16: ; preds = %31, %15
%17 = load i32, i32* %10
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32*, i32** %6
%26 = call i32 @fread(i8* %24, i32 1, i32 1, i32* %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 1, i32* %5
br label %58
30: ; preds = %20
br label %31
31: ; preds = %30
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %16
34: ; preds = %16
br label %57
35: ; preds = %4
store i32 0, i32* %10
br label %36
36: ; preds = %53, %35
%37 = load i32, i32* %10
%38 = load i32, i32* %9
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %36
%41 = load i32*, i32** %6
%42 = call i32 @fscanf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %5
br label %58
46: ; preds = %40
%47 = load i32, i32* %12
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %8
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
br label %53
53: ; preds = %46
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %36
56: ; preds = %36
br label %57
57: ; preds = %56, %34
store i32 0, i32* %5
br label %58
58: ; preds = %57, %45, %29
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @readCVec(i32* nocapture %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32 %1, 3
%8 = icmp sgt i32 %3, 0
br i1 %7, label %12, label %9
9: ; preds = %4
br i1 %8, label %10, label %33
10: ; preds = %9
%11 = zext i32 %3 to i64
br label %23
12: ; preds = %4
br i1 %8, label %13, label %33
13: ; preds = %12
%14 = zext i32 %3 to i64
br label %17
15: ; preds = %17
%16 = icmp eq i64 %22, %14
br i1 %16, label %33, label %17
17: ; preds = %13, %15
%18 = phi i64 [ 0, %13 ], [ %22, %15 ]
%19 = getelementptr inbounds i8, i8* %2, i64 %18
%20 = tail call i32 @fread(i8* %19, i32 1, i32 1, i32* %0)
%21 = icmp eq i32 %20, 1
%22 = add nuw nsw i64 %18, 1
br i1 %21, label %15, label %33
23: ; preds = %10, %27
%24 = phi i64 [ 0, %10 ], [ %31, %27 ]
%25 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %5
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %2, i64 %24
store i8 %29, i8* %30
%31 = add nuw nsw i64 %24, 1
%32 = icmp eq i64 %31, %11
br i1 %32, label %33, label %23
33: ; preds = %23, %27, %17, %15, %9, %12
%34 = phi i32 [ 0, %12 ], [ 0, %9 ], [ 1, %17 ], [ 0, %15 ], [ 1, %23 ], [ 0, %27 ]
ret i32 %34
}