#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 */
unsigned int atoi(char *);
int fgetc(int /*<<< orphan*/ *);
scalar_t__ isdigit(int);
int /*<<< orphan*/ skip_white_space(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
unsigned int read_uint(FILE *fp) {
  int i;
  char buf[80];
  int ch;
  skip_white_space(fp);
  ch = -1;
  for (i = 0; i < 80 - 1 && isdigit(ch = fgetc(fp)); i++)
    buf[i] = ch;
  buf[i] = '\0';
  if (i == 0) {
    return (-1);
  }
  ungetc(ch, fp);
  return (atoi(buf));
}


x86 assembly (clang, -O0):
<read_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <skip_white_space@plt>
movl   $0xffffffff,-0x74(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x4f,-0x14(%rbp)
mov    %al,-0x75(%rbp)
jge    11a2 <read_uint+0x52>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%edi
mov    %edi,-0x74(%rbp)
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    11b2 <read_uint+0x62>
jmp    11cd <read_uint+0x7d>
mov    -0x74(%rbp),%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <read_uint+0x26>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
cmpl   $0x0,-0x14(%rbp)
jne    11ec <read_uint+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <read_uint+0xb4>
mov    -0x74(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ungetc@plt>
lea    -0x70(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_uint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r14
call   1050 <skip_white_space@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     119b <read_uint+0x4b>
mov    %bpl,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x4f,%rbx
jne    1170 <read_uint+0x20>
movb   $0x0,0x4f(%rsp)
jmp    11a3 <read_uint+0x53>
movb   $0x0,(%rsp,%rbx,1)
test   %ebx,%ebx
je     11b7 <read_uint+0x67>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <ungetc@plt>
mov    %rsp,%rdi
call   1070 <atoi@plt>
jmp    11bc <read_uint+0x6c>
mov    $0xffffffff,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_uint(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @skip_white_space(i32* %7)
store i32 -1, i32* %6
store i32 0, i32* %4
br label %9
9: ; preds = %25, %1
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 79
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %6
%15 = call i64 @isdigit(i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = load i32, i32* %6
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %17
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 -1, i32* %2
br label %41
35: ; preds = %28
%36 = load i32, i32* %6
%37 = load i32*, i32** %3
%38 = call i32 @ungetc(i32 %36, i32* %37)
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %2
br label %41
41: ; preds = %35, %34
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @read_uint(i32* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @skip_white_space(i32* %0)
br label %7
5: ; preds = %12
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 79
store i8 0, i8* %6
br label %22
7: ; preds = %1, %12
%8 = phi i64 [ 0, %1 ], [ %15, %12 ]
%9 = tail call i32 @fgetc(i32* %0)
%10 = tail call i64 @isdigit(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = trunc i32 %9 to i8
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %8
store i8 %13, i8* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, 79
br i1 %16, label %5, label %7
17: ; preds = %7
%18 = trunc i64 %8 to i32
%19 = and i64 %8, 4294967295
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = icmp eq i32 %18, 0
br i1 %21, label %25, label %22
22: ; preds = %5, %17
%23 = tail call i32 @ungetc(i32 %9, i32* %0)
%24 = call i32 @atoi(i8* %3)
br label %25
25: ; preds = %17, %22
%26 = phi i32 [ %24, %22 ], [ -1, %17 ]
ret i32 %26
}