#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);
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");
    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    1205 <maxLitho+0xb5>
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)
mov    -0x128(%rbp),%rdi
lea    0xe44(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    11eb <maxLitho+0x9b>
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    0xdff(%rip),%rdi
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    11fb <maxLitho+0xab>
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     11f5 <maxLitho+0xa5>
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
mov    %rax,%rdi
lea    0xe33(%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    11fd <maxLitho+0xad>
xor    %esi,%esi
lea    0xe0d(%rip),%rdi
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 = [3 x i8] c"%d\00"
@.str.3 = [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 = %36, %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 %39
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 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%26 = load i32, i32* %8
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = icmp sgt i32 %26, %28
br i1 %29, label %30, label %33
30: ; preds = %17
%31 = load i32, i32* %8
%32 = load i32*, i32** %5
store i32 %31, i32* %32
br label %33
33: ; preds = %30, %17
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %12
39: ; preds = %12
%40 = load i32*, i32** %5
%41 = load i32, i32* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %41)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s_%04d.g22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [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 %24, label %9
9: ; preds = %3, %18
%10 = phi i32 [ %20, %18 ], [ 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 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%14 = load i32, i32* %4
%15 = load i32, i32* %1
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %9
store i32 %14, i32* %1
br label %18
18: ; preds = %17, %9
%19 = call i32 @fclose(i32* %12)
%20 = add nuw i32 %10, 1
%21 = icmp eq i32 %10, %2
br i1 %21, label %22, label %9
22: ; preds = %18
%23 = load i32, i32* %1
br label %24
24: ; preds = %22, %3
%25 = phi i32 [ %23, %22 ], [ 0, %3 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret void
}