#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void read_build(char const *name, int *pbuild) {
  FILE *f;
  if (pbuild)
    *pbuild = 0;
  if (!(f = fopen(name, "r")))
    return;
  if (fscanf(f, "%d", pbuild) != 1) {
    fprintf(stderr, "%s: cannot read build number\n", name);
    exit(1);
  }
  fscanf(f, " ");
  if (getc(f) != EOF) {
    fprintf(stderr, "%s: garbage after build number\n", name);
    exit(1);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<read_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1185 <read_build+0x25>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a8 <read_build+0x48>
jmp    1241 <read_build+0xe1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11ea <read_build+0x8a>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     1238 <read_build+0xd8>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_build>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
test   %rsi,%rsi
je     1177 <read_build+0x17>
movl   $0x0,(%r15)
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d9 <read_build+0x79>
mov    %rax,%rbx
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11df <read_build+0x7f>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
jne    11f1 <read_build+0x91>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
jmp    1201 <read_build+0xa1>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s: cannot read build number\0A\00"
@.str.3 = [2 x i8] c" \00"
@EOF = global i64 0
@.str.4 = [32 x i8] c"%s: garbage after build number\0A\00"
define void @read_build(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32*, i32** %4
store i32 0, i32* %9
br label %10
10: ; preds = %8, %2
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %10
br label %40
15: ; preds = %10
%16 = load i32*, i32** %5
%17 = load i32*, i32** %4
%18 = call i32 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = load i32*, i32** %5
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32*, i32** %5
%29 = call i64 @getc(i32* %28)
%30 = load i64, i64* @EOF
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %3
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %25
%38 = load i32*, i32** %5
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %14
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s: cannot read build number\0A\00"
@.str.3 = [2 x i8] c" \00"
@EOF = global i64 0
@.str.4 = [32 x i8] c"%s: garbage after build number\0A\00"
define void @read_build(i8* %0, i32* %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %5, label %4
4: ; preds = %2
store i32 0, i32* %1
br label %5
5: ; preds = %4, %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %26, label %8
8: ; preds = %5
%9 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i64 @getc(i32* %6)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = tail call i32 @fclose(i32* %6)
br label %26
26: ; preds = %5, %24
ret void
}