#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char **, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void read_header(char *rootname, int *nx, int *ny, int *nz, int *nevents,
                 double *xOff, double *yOff, double *zOff, double *scale) {
  FILE *in;
  char fname[250];
  char dum1[250], dum2[250];
  sprintf(fname, "%s.g20", rootname);
  printf("%s %s\n", fname, rootname);
  in = fopen(fname, "r");
  if (in == NULL) {
    printf("Error: Could not open %s\n", rootname);
  }
  fscanf(in, "%s %s %d", &dum1, &dum2, nevents);
  printf("#events %d\n", *nevents);
  fscanf(in, "%s %d %d %d", &dum1, nx, ny, nz);
  printf("dim x=%d y=%d z=%d\n", *nx, *ny, *nz);
  fscanf(in, "%s %s %lf %lf %lf %lf", &dum1, &dum2, xOff, yOff, zOff, scale);
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x140(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x140(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d3 <read_header+0x93>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x240(%rbp),%rdx
mov    -0x28(%rbp),%r8
lea    0xe41(%rip),%rsi
lea    -0x340(%rbp),%rcx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x240(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x240(%rbp),%rdx
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r9
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
lea    0xded(%rip),%rsi
lea    -0x340(%rbp),%rcx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <fscanf@plt>
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%r14
mov    %rcx,(%rsp)
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe93(%rip),%rsi
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
lea    0xe80(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe73(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11bc <read_header+0x7c>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe67(%rip),%rsi
lea    0x110(%rsp),%r15
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%r14),%esi
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    (%rsp),%rbx
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%r12),%esi
mov    0x0(%r13),%edx
mov    (%rbx),%ecx
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe2e(%rip),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
lea    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    0x350(%rsp),%r9
xor    %eax,%eax
push   0x360(%rsp)
push   0x360(%rsp)
call   1040 <fscanf@plt>
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s.g20\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"Error: Could not open %s\0A\00"
@.str.4 = [9 x i8] c"%s %s %d\00"
@.str.5 = [12 x i8] c"#events %d\0A\00"
@.str.6 = [12 x i8] c"%s %d %d %d\00"
@.str.7 = [20 x i8] c"dim x=%d y=%d z=%d\0A\00"
@.str.8 = [22 x i8] c"%s %s %lf %lf %lf %lf\00"
define void @read_header(i8* %0, i32* %1, i32* %2, i32* %3, i32* %4, double* %5, double* %6, double* %7, double* %8) {
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca i32*
%20 = alloca [250 x i8]
%21 = alloca [250 x i8]
%22 = alloca [250 x i8]
store i8* %0, i8** %10
store i32* %1, i32** %11
store i32* %2, i32** %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store double* %5, double** %15
store double* %6, double** %16
store double* %7, double** %17
store double* %8, double** %18
%23 = getelementptr inbounds [250 x i8], [250 x i8]* %20, i64 0, i64 0
%24 = load i8*, i8** %10
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [250 x i8], [250 x i8]* %20, i64 0, i64 0
%27 = load i8*, i8** %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [250 x i8], [250 x i8]* %20, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %19
%31 = load i32*, i32** %19
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %9
%34 = load i8*, i8** %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %9
%37 = load i32*, i32** %19
%38 = bitcast [250 x i8]* %21 to i8**
%39 = load i32*, i32** %14
%40 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %38, [250 x i8]* %22, i32* %39)
%41 = load i32*, i32** %14
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = load i32*, i32** %19
%45 = bitcast [250 x i8]* %21 to i8**
%46 = load i32*, i32** %11
%47 = load i32*, i32** %12
%48 = load i32*, i32** %13
%49 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %45, i32* %46, i32* %47, i32* %48)
%50 = load i32*, i32** %11
%51 = load i32, i32* %50
%52 = load i32*, i32** %12
%53 = load i32, i32* %52
%54 = load i32*, i32** %13
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %51, i32 %53, i32 %55)
%57 = load i32*, i32** %19
%58 = bitcast [250 x i8]* %21 to i8**
%59 = load double*, double** %15
%60 = load double*, double** %16
%61 = load double*, double** %17
%62 = load double*, double** %18
%63 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8** %58, [250 x i8]* %22, double* %59, double* %60, double* %61, double* %62)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s.g20\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"Error: Could not open %s\0A\00"
@.str.4 = [9 x i8] c"%s %s %d\00"
@.str.5 = [12 x i8] c"#events %d\0A\00"
@.str.6 = [12 x i8] c"%s %d %d %d\00"
@.str.7 = [20 x i8] c"dim x=%d y=%d z=%d\0A\00"
@.str.8 = [22 x i8] c"%s %s %lf %lf %lf %lf\00"
define void @read_header(i8* %0, i32* %1, i32* %2, i32* %3, i32* %4, double* %5, double* %6, double* %7, double* %8) {
%10 = alloca [250 x i8]
%11 = alloca [250 x i8]
%12 = alloca [250 x i8]
%13 = getelementptr inbounds [250 x i8], [250 x i8]* %10, i64 0, i64 0
%14 = getelementptr inbounds [250 x i8], [250 x i8]* %11, i64 0, i64 0
%15 = getelementptr inbounds [250 x i8], [250 x i8]* %12, i64 0, i64 0
%16 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %0)
%18 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %20, %9
%23 = bitcast [250 x i8]* %11 to i8**
%24 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %23, [250 x i8]* %12, i32* %4)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %23, i32* %1, i32* %2, i32* %3)
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
%32 = call i32 (i32*, i8*, i8**, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8** %23, [250 x i8]* %12, double* %5, double* %6, double* %7, double* %8)
ret void
}