#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ isdigit(int);
int capture_int(const char *f, int def) {
  FILE *fp;
  int o = 0, c;
  fp = fopen(f, "r");
  if (!fp)
    return def;
  for (;;) {
    c = fgetc(fp);
    if (c == -1)
      break;
    if (!isdigit(c))
      break;
    o *= 10;
    o += (c - '0');
  }
  (void)fclose(fp);
  if (o == 0)
    return def;
  return o;
}


x86 assembly (clang, -O0):
<capture_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1180 <capture_int+0x40>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <capture_int+0xb2>
jmp    1185 <capture_int+0x45>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11a0 <capture_int+0x60>
jmp    11ce <capture_int+0x8e>
mov    -0x28(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b6 <capture_int+0x76>
jmp    11ce <capture_int+0x8e>
imul   $0xa,-0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x30,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <capture_int+0x45>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11ec <capture_int+0xac>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <capture_int+0xb2>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capture_int>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1192 <capture_int+0x62>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
lea    -0x30(%rax),%ecx
cmp    $0x9,%ecx
ja     118a <capture_int+0x5a>
xor    %ebp,%ebp
nopl   (%rax)
lea    0x0(%rbp,%rbp,4),%ecx
lea    (%rax,%rcx,2),%ebp
add    $0xffffffd0,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
jb     1160 <capture_int+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
jne    1195 <capture_int+0x65>
jmp    1192 <capture_int+0x62>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @capture_int(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = load i32, i32* %5
store i32 %14, i32* %3
br label %43
15: ; preds = %2
br label %16
16: ; preds = %27, %15
%17 = load i32*, i32** %6
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
br label %34
22: ; preds = %16
%23 = load i32, i32* %8
%24 = call i32 @isdigit(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
br label %34
27: ; preds = %22
%28 = load i32, i32* %7
%29 = mul nsw i32 %28, 10
store i32 %29, i32* %7
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, 48
%32 = load i32, i32* %7
%33 = add nsw i32 %32, %31
store i32 %33, i32* %7
br label %16
34: ; preds = %26, %21
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i32, i32* %5
store i32 %40, i32* %3
br label %43
41: ; preds = %34
%42 = load i32, i32* %7
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %39, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @capture_int(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = tail call i32 @fgetc(i32* %3)
%7 = add i32 %6, -48
%8 = icmp ult i32 %7, 10
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @fclose(i32* %3)
br label %23
11: ; preds = %5, %11
%12 = phi i32 [ %17, %11 ], [ %6, %5 ]
%13 = phi i32 [ %16, %11 ], [ 0, %5 ]
%14 = add nsw i32 %12, -48
%15 = mul nsw i32 %13, 10
%16 = add nsw i32 %14, %15
%17 = tail call i32 @fgetc(i32* %3)
%18 = add i32 %17, -48
%19 = icmp ult i32 %18, 10
br i1 %19, label %11, label %20
20: ; preds = %11
%21 = tail call i32 @fclose(i32* %3)
%22 = icmp eq i32 %16, 0
br i1 %22, label %23, label %24
23: ; preds = %9, %20
br label %24
24: ; preds = %23, %20, %2
%25 = phi i32 [ %1, %2 ], [ %1, %23 ], [ %16, %20 ]
ret i32 %25
}