#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 */
struct tweet_dB_t {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ GetNextDb(struct tweet_dB_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned int,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int GetNthDb(unsigned n, unsigned prev, struct tweet_dB_t *tweetDbL,
             FILE *fin) {
  unsigned tcnt = 0, length;
  if (fin == NULL) {
    printf("DBfile file not found\n");
    exit(1);
  }
  if (n < prev) {
    fseek(fin, 0, SEEK_SET);
    prev = 0;
  }
  for (tcnt = 0; tcnt < (n - prev); tcnt++) {
    fseek(fin, 1 * sizeof(unsigned), SEEK_CUR);
    if (feof(fin))
      return 0;
    fread(&length, sizeof(unsigned), 1, fin);
    if (feof(fin))
      return 0;
    fseek(fin, length * sizeof(unsigned), SEEK_CUR);
    if (length > 45)
      printf("WARNING Something wrong %u\n", length);
  }
  GetNextDb(tweetDbL, fin);
  return tcnt;
}


x86 assembly (clang, -O0):
<GetNthDb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a0 <GetNthDb+0x40>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11c7 <GetNthDb+0x67>
mov    -0x20(%rbp),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jae    1294 <GetNthDb+0x134>
mov    -0x20(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1215 <GetNthDb+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    12a7 <GetNthDb+0x147>
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     124b <GetNthDb+0xeb>
movl   $0x0,-0x4(%rbp)
jmp    12a7 <GetNthDb+0x147>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
cmpl   $0x2d,-0x28(%rbp)
jbe    1281 <GetNthDb+0x121>
mov    -0x28(%rbp),%esi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1286 <GetNthDb+0x126>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ce <GetNthDb+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <GetNextDb@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetNthDb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rcx,%rcx
je     1266 <GetNthDb+0xf6>
mov    %rcx,%rbx
mov    %esi,%ebp
mov    %edi,%r12d
mov    %rdx,0x10(%rsp)
cmp    %esi,%edi
jae    11ad <GetNthDb+0x3d>
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
sub    %ebp,%r12d
je     1242 <GetNthDb+0xd2>
mov    0x2e2b(%rip),%r14
lea    0xc(%rsp),%r15
mov    %r12d,%r13d
jmp    11d6 <GetNthDb+0x66>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%r13d
je     1242 <GetNthDb+0xd2>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1251 <GetNthDb+0xe1>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1251 <GetNthDb+0xe1>
mov    0xc(%rsp),%ebp
lea    0x0(,%rbp,4),%esi
mov    (%r14),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
cmp    $0x2e,%ebp
jb     11d0 <GetNthDb+0x60>
lea    0xdc9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d0 <GetNthDb+0x60>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <GetNextDb@plt>
jmp    1254 <GetNthDb+0xe4>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tweet_dB_t = type { i32 }
@.str = [23 x i8] c"DBfile file not found\0A\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [28 x i8] c"WARNING Something wrong %u\0A\00"
define i32 @GetNthDb(i32 %0, i32 %1, %struct.tweet_dB_t* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tweet_dB_t*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store %struct.tweet_dB_t* %2, %struct.tweet_dB_t** %8
store i32* %3, i32** %9
store i32 0, i32* %10
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %4
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32*, i32** %9
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
store i32 0, i32* %7
br label %25
25: ; preds = %21, %17
store i32 0, i32* %10
br label %26
26: ; preds = %61, %25
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = sub i32 %28, %29
%31 = icmp ult i32 %27, %30
br i1 %31, label %32, label %64
32: ; preds = %26
%33 = load i32*, i32** %9
%34 = load i32, i32* @SEEK_CUR
%35 = call i32 @fseek(i32* %33, i32 4, i32 %34)
%36 = load i32*, i32** %9
%37 = call i64 @feof(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 0, i32* %5
br label %69
40: ; preds = %32
%41 = load i32*, i32** %9
%42 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %41)
%43 = load i32*, i32** %9
%44 = call i64 @feof(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 0, i32* %5
br label %69
47: ; preds = %40
%48 = load i32*, i32** %9
%49 = load i32, i32* %11
%50 = zext i32 %49 to i64
%51 = mul i64 %50, 4
%52 = trunc i64 %51 to i32
%53 = load i32, i32* @SEEK_CUR
%54 = call i32 @fseek(i32* %48, i32 %52, i32 %53)
%55 = load i32, i32* %11
%56 = icmp ugt i32 %55, 45
br i1 %56, label %57, label %60
57: ; preds = %47
%58 = load i32, i32* %11
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %47
br label %61
61: ; preds = %60
%62 = load i32, i32* %10
%63 = add i32 %62, 1
store i32 %63, i32* %10
br label %26
64: ; preds = %26
%65 = load %struct.tweet_dB_t*, %struct.tweet_dB_t** %8
%66 = load i32*, i32** %9
%67 = call i32 @GetNextDb(%struct.tweet_dB_t* %65, i32* %66)
%68 = load i32, i32* %10
store i32 %68, i32* %5
br label %69
69: ; preds = %64, %46, %39
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
%struct.tweet_dB_t = type { i32 }
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [28 x i8] c"WARNING Something wrong %u\0A\00"
@str = [22 x i8] c"DBfile file not found\00"
define i32 @GetNthDb(i32 %0, i32 %1, %struct.tweet_dB_t* %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32* %3, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = icmp ult i32 %0, %1
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %3, i32 0, i32 %14)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ 0, %13 ], [ %1, %11 ]
%18 = sub i32 %0, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %16, %38
%21 = phi i32 [ %39, %38 ], [ 0, %16 ]
%22 = load i32, i32* @SEEK_CUR
%23 = tail call i32 @fseek(i32* %3, i32 4, i32 %22)
%24 = tail call i64 @feof(i32* %3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %20
%27 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %3)
%28 = tail call i64 @feof(i32* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i32, i32* %5
%32 = shl i32 %31, 2
%33 = load i32, i32* @SEEK_CUR
%34 = tail call i32 @fseek(i32* %3, i32 %32, i32 %33)
%35 = icmp ugt i32 %31, 45
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %38
38: ; preds = %30, %36
%39 = add nuw i32 %21, 1
%40 = icmp eq i32 %39, %18
br i1 %40, label %41, label %20
41: ; preds = %38, %16
%42 = tail call i32 @GetNextDb(%struct.tweet_dB_t* %2, i32* %3)
br label %43
43: ; preds = %26, %20, %41
%44 = phi i32 [ %18, %41 ], [ 0, %20 ], [ 0, %26 ]
ret i32 %44
}