#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int32_t read_uint32(void) {
  char string[12] = {0};
  char *position = NULL;
  if (fgets(string, 11, stdin) != NULL) {
    position = strchr(string, '\n');
    if (position != NULL) {
      *position = '\0';
    } else {
      int c = 0;
      while (c != '\n' && c != EOF)
        c = getchar();
    }
    return (uint32_t)strtol(string, NULL, 10);
  } else {
    int c = 0;
    while (c != 'n' && c != EOF)
      c = getchar();
    return -1;
  }
}


x86 assembly (clang, -O0):
<read_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
movq   $0x0,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    $0xb,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1220 <read_uint32+0xd0>
lea    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ba <read_uint32+0x6a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1206 <read_uint32+0xb6>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
je     11e2 <read_uint32+0x92>
mov    -0x1c(%rbp),%eax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11f2 <read_uint32+0xa2>
jmp    1201 <read_uint32+0xb1>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x1c(%rbp)
jmp    11c1 <read_uint32+0x71>
jmp    1206 <read_uint32+0xb6>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x4(%rbp)
jmp    126e <read_uint32+0x11e>
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x6e,-0x20(%rbp)
mov    %al,-0x22(%rbp)
je     1248 <read_uint32+0xf8>
mov    -0x20(%rbp),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1258 <read_uint32+0x108>
jmp    1267 <read_uint32+0x117>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x20(%rbp)
jmp    1227 <read_uint32+0xd7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_uint32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0xb,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     118d <read_uint32+0x4d>
lea    0x8(%rsp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11b2 <read_uint32+0x72>
movb   $0x0,(%rax)
jmp    11d0 <read_uint32+0x90>
mov    0x2e4c(%rip),%rbx
mov    $0xffffffff,%ebp
cmpl   $0x0,(%rbx)
je     11e3 <read_uint32+0xa3>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x6e,%eax
je     11e3 <read_uint32+0xa3>
cmp    (%rbx),%eax
jne    11a0 <read_uint32+0x60>
jmp    11e3 <read_uint32+0xa3>
mov    0x2e27(%rip),%rbx
cmpl   $0x0,(%rbx)
je     11d0 <read_uint32+0x90>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11d0 <read_uint32+0x90>
cmp    (%rbx),%eax
jne    11c0 <read_uint32+0x80>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i32 @read_uint32() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [12 x i8]* %2 to i8*
store i8* null, i8** %3
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %7, i32 11, i32 %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %34
11: ; preds = %0
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %3
store i8 0, i8* %17
br label %31
18: ; preds = %11
store i32 0, i32* %4
br label %19
19: ; preds = %28, %18
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %4
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br label %26
26: ; preds = %22, %19
%27 = phi i1 [ false, %19 ], [ %25, %22 ]
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 (...) @getchar()
store i32 %29, i32* %4
br label %19
30: ; preds = %26
br label %31
31: ; preds = %30, %16
%32 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%33 = call i32 @strtol(i8* %32, i32* null, i32 10)
store i32 %33, i32* %1
br label %47
34: ; preds = %0
store i32 0, i32* %5
br label %35
35: ; preds = %44, %34
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 110
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* %5
%40 = load i32, i32* @EOF
%41 = icmp ne i32 %39, %40
br label %42
42: ; preds = %38, %35
%43 = phi i1 [ false, %35 ], [ %41, %38 ]
br i1 %43, label %44, label %46
44: ; preds = %42
%45 = call i32 (...) @getchar()
store i32 %45, i32* %5
br label %35
46: ; preds = %42
store i32 -1, i32* %1
br label %47
47: ; preds = %46, %31
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i32 @read_uint32() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 11, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %7, 0
br i1 %8, label %30, label %24
9: ; preds = %0
%10 = call i8* @strchr(i8* %2, i8 signext 10)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %16
15: ; preds = %9
store i8 0, i8* %10
br label %22
16: ; preds = %12, %16
%17 = call i32 (...) @getchar()
%18 = icmp ne i32 %17, 10
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %17, %19
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %16, label %22
22: ; preds = %16, %12, %15
%23 = call i32 @strtol(i8* nocapture %2, i32* null, i32 10)
br label %30
24: ; preds = %6, %24
%25 = call i32 (...) @getchar()
%26 = icmp ne i32 %25, 110
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %25, %27
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %24, label %30
30: ; preds = %24, %6, %22
%31 = phi i32 [ %23, %22 ], [ -1, %6 ], [ -1, %24 ]
ret i32 %31
}