#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*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
unsigned int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
unsigned int getdisp(FILE *file, int i) {
  unsigned int factor = 1;
  unsigned int disp = 0;
  char x[2];
  while (i > 0) {
    fgetc(file);
    disp += factor * strtol(fgets(x, 3, file), NULL, 16);
    factor *= 256;
    i--;
  }
  return disp;
}


x86 assembly (clang, -O0):
<getdisp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11ad <getdisp+0x7d>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3,%esi
call   1040 <fgets@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <getdisp+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdisp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1199 <getdisp+0x69>
mov    %esi,%ebx
mov    %rdi,%r14
add    $0x1,%ebx
mov    $0x1,%ebp
xor    %r15d,%r15d
lea    0xe(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %r12,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
imul   %ebp,%eax
add    %eax,%r15d
shl    $0x8,%ebp
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1160 <getdisp+0x30>
jmp    119c <getdisp+0x6c>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getdisp(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %11, %2
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = call i32 @fgetc(i32* %12)
%14 = load i32, i32* %5
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @fgets(i8* %15, i32 3, i32* %16)
%18 = call i32 @strtol(i32 %17, i32* null, i32 16)
%19 = mul i32 %14, %18
%20 = load i32, i32* %6
%21 = add i32 %20, %19
store i32 %21, i32* %6
%22 = load i32, i32* %5
%23 = mul i32 %22, 256
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %8
26: ; preds = %8
%27 = load i32, i32* %6
ret i32 %27
}

LLVM IR (-O2):
define i32 @getdisp(i32* nocapture %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %2, %6
%7 = phi i32 [ %14, %6 ], [ 0, %2 ]
%8 = phi i32 [ %15, %6 ], [ 1, %2 ]
%9 = phi i32 [ %16, %6 ], [ %1, %2 ]
%10 = call i32 @fgetc(i32* %0)
%11 = call i32 @fgets(i8* %4, i32 3, i32* %0)
%12 = call i32 @strtol(i32 %11, i32* null, i32 16)
%13 = mul i32 %12, %8
%14 = add i32 %13, %7
%15 = shl i32 %8, 8
%16 = add nsw i32 %9, -1
%17 = icmp ugt i32 %9, 1
br i1 %17, label %6, label %18
18: ; preds = %6, %2
%19 = phi i32 [ 0, %2 ], [ %14, %6 ]
ret i32 %19
}