#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int get_total_number_of_groups(int argc, void *argv[]) {
  int Ngroups, Nids, TotNgroups, NTask, Num;
  char *OutputDir;
  char buf[1000];
  FILE *fd;
  OutputDir = (char *)argv[0];
  Num = *(int *)argv[1];
  sprintf(buf, "%s/group_tab_%03d.0", OutputDir, Num);
  if (!(fd = fopen(buf, "r"))) {
    printf("path: %s\n", buf);
    return -1;
  }
  fread(&Ngroups, sizeof(int), 1, fd);
  fread(&Nids, sizeof(int), 1, fd);
  fread(&TotNgroups, sizeof(int), 1, fd);
  fread(&NTask, sizeof(int), 1, fd);
  fclose(fd);
  return TotNgroups;
}


x86 assembly (clang, -O0):
<get_total_number_of_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe71(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    11d7 <get_total_number_of_groups+0x87>
lea    -0x420(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <get_total_number_of_groups+0x101>
mov    -0x428(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x428(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x428(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x428(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_total_number_of_groups>:
push   %rbx
sub    $0x400,%rsp
mov    (%rsi),%rdx
mov    0x8(%rsi),%rax
mov    (%rax),%ecx
lea    0xe98(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f3 <get_total_number_of_groups+0xa3>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%eax
jmp    1209 <get_total_number_of_groups+0xb9>
lea    0xe1c(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s/group_tab_%03d.0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"path: %s\0A\00"
define i32 @get_total_number_of_groups(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [1000 x i8]
%13 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
store i8* %16, i8** %11
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = bitcast i8* %19 to i32*
%21 = load i32, i32* %20
store i32 %21, i32* %10
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%23 = load i8*, i8** %11
%24 = load i32, i32* %10
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24)
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %13
%28 = icmp ne i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %2
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %44
32: ; preds = %2
%33 = load i32*, i32** %13
%34 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %33)
%35 = load i32*, i32** %13
%36 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %35)
%37 = load i32*, i32** %13
%38 = call i32 @fread(i32* %8, i32 4, i32 1, i32* %37)
%39 = load i32*, i32** %13
%40 = call i32 @fread(i32* %9, i32 4, i32 1, i32* %39)
%41 = load i32*, i32** %13
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %8
store i32 %43, i32* %3
br label %44
44: ; preds = %32, %29
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s/group_tab_%03d.0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"path: %s\0A\00"
define i32 @get_total_number_of_groups(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1000 x i8]
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = bitcast i8** %14 to i32**
%16 = load i32*, i32** %15
%17 = load i32, i32* %16
%18 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %17)
%19 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %30
23: ; preds = %2
%24 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %19)
%25 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %19)
%26 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %19)
%27 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %19)
%28 = tail call i32 @fclose(i32* %19)
%29 = load i32, i32* %5
br label %30
30: ; preds = %23, %21
%31 = phi i32 [ %29, %23 ], [ -1, %21 ]
ret i32 %31
}