#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
void maxLitho(char *root, int *nlitho, int files) {
  int n, localnlitho;
  char rootname[250];
  FILE *in;
  *nlitho = 0;
  for (n = 1; n < files + 1; n++) {
    sprintf(rootname, "%s_%04d.g22", root, n);
    in = fopen(rootname, "r");
    if (in == NULL) {
      printf("Error: Could not open %s\n", rootname);
    }
    fscanf(in, "%d", &localnlitho);
    if (localnlitho > *nlitho)
      *nlitho = localnlitho;
    fclose(in);
  }
  printf("max litho %d\n", *nlitho);
}


x86 assembly (clang, -O0):
<maxLitho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1228 <maxLitho+0xd8>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe63(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11df <maxLitho+0x8f>
lea    -0x120(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%rdi
lea    0xe3b(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    120e <maxLitho+0xbe>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1177 <maxLitho+0x27>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxLitho>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x0,(%rsi)
test   %edx,%edx
jle    1211 <maxLitho+0xc1>
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r15
neg    %r14d
mov    $0x1,%ebx
lea    0x10(%rsp),%rbp
jmp    11ab <maxLitho+0x5b>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     120b <maxLitho+0xbb>
mov    %rbp,%rdi
lea    0xe4b(%rip),%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
lea    0xe43(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11e7 <maxLitho+0x97>
lea    0xe31(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
lea    0xe37(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <fscanf@plt>
mov    0xc(%rsp),%eax
cmp    0x0(%r13),%eax
jle    1190 <maxLitho+0x40>
mov    %eax,0x0(%r13)
jmp    1190 <maxLitho+0x40>
mov    0x0(%r13),%esi
jmp    1213 <maxLitho+0xc3>
xor    %esi,%esi
lea    0xe11(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s_%04d.g22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Error: Could not open %s\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"max litho %d\0A\00"
define void @maxLitho(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [250 x i8]
%10 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = load i32*, i32** %5
store i32 0, i32* %11
store i32 1, i32* %7
br label %12
12: ; preds = %42, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %45
17: ; preds = %12
%18 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %20)
%22 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = getelementptr inbounds [250 x i8], [250 x i8]* %9, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %17
%30 = load i32*, i32** %10
%31 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%32 = load i32, i32* %8
%33 = load i32*, i32** %5
%34 = load i32, i32* %33
%35 = icmp sgt i32 %32, %34
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32, i32* %8
%38 = load i32*, i32** %5
store i32 %37, i32* %38
br label %39
39: ; preds = %36, %29
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %12
45: ; preds = %12
%46 = load i32*, i32** %5
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %47)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s_%04d.g22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Error: Could not open %s\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"max litho %d\0A\00"
define void @maxLitho(i8* %0, i32* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = alloca [250 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [250 x i8], [250 x i8]* %5, i64 0, i64 0
store i32 0, i32* %1
%8 = icmp slt i32 %2, 1
br i1 %8, label %28, label %9
9: ; preds = %3, %22
%10 = phi i32 [ %24, %22 ], [ 1, %3 ]
%11 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %10)
%12 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %16
16: ; preds = %14, %9
%17 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = load i32, i32* %1
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 %18, i32* %1
br label %22
22: ; preds = %21, %16
%23 = call i32 @fclose(i32* %12)
%24 = add nuw i32 %10, 1
%25 = icmp eq i32 %10, %2
br i1 %25, label %26, label %9
26: ; preds = %22
%27 = load i32, i32* %1
br label %28
28: ; preds = %26, %3
%29 = phi i32 [ %27, %26 ], [ 0, %3 ]
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %29)
ret void
}