#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 */

/* Variables and functions */
int /*<<< orphan*/ scanf(char *, unsigned char *);
unsigned int readInt(int size) {
  int i;
  unsigned int res = 0;
  for (i = 0; i < size; i++) {
    unsigned char c;
    scanf("%c", &c);
    res += (c << (8 * i));
  }
  return res;
}


x86 assembly (clang, -O0):
<readInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1165 <readInt+0x55>
lea    0xec4(%rip),%rdi
lea    -0xd(%rbp),%rsi
call   1030 <scanf@plt>
movzbl -0xd(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <readInt+0x19>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    1161 <readInt+0x51>
mov    %edi,%r14d
xor    %ebp,%ebp
lea    0xed4(%rip),%r15
lea    0xf(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <scanf@plt>
movzbl 0xf(%rsp),%eax
mov    %ebp,%ecx
shl    %cl,%eax
add    %eax,%ebx
add    $0x8,%ebp
add    $0xffffffff,%r14d
jne    1140 <readInt+0x30>
jmp    1163 <readInt+0x53>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i32 @readInt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%12 = load i8, i8* %5
%13 = zext i8 %12 to i32
%14 = load i32, i32* %3
%15 = mul nsw i32 8, %14
%16 = shl i32 %13, %15
%17 = load i32, i32* %4
%18 = add i32 %17, %16
store i32 %18, i32* %4
br label %19
19: ; preds = %10
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define i32 @readInt(i32 %0) {
%2 = alloca i8
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %15
4: ; preds = %1, %4
%5 = phi i32 [ %12, %4 ], [ 0, %1 ]
%6 = phi i32 [ %13, %4 ], [ 0, %1 ]
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = shl nsw i32 %6, 3
%11 = shl i32 %9, %10
%12 = add i32 %11, %5
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %4
15: ; preds = %4, %1
%16 = phi i32 [ 0, %1 ], [ %12, %4 ]
ret i32 %16
}