#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 EOF;
int fscanf(int /*<<< orphan*/ *, char *, char *);
int read_line(FILE *f, char *loc, char *label, char *opcode, char *operand) {
  int bytes = 0, t;
  bytes += ((t = fscanf(f, "%s", loc)) == EOF) ? 0 : t;
  bytes += ((t = fscanf(f, "%s", label)) == EOF) ? 0 : t;
  bytes += ((t = fscanf(f, "%s", opcode)) == EOF) ? 0 : t;
  bytes += ((t = fscanf(f, "%s", operand)) == EOF) ? 0 : t;
  return bytes;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xebe(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%eax
jne    1163 <read_line+0x53>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <read_line+0x59>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    11a2 <read_line+0x92>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11a8 <read_line+0x98>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jne    11e1 <read_line+0xd1>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e7 <read_line+0xd7>
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x30(%rbp)
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%eax
jne    1220 <read_line+0x110>
xor    %eax,%eax
mov    %eax,-0x40(%rbp)
jmp    1226 <read_line+0x116>
mov    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r13
mov    %rsi,%rdx
mov    %rdi,%r14
lea    0xec8(%rip),%r12
mov    %r12,%rsi
call   1030 <fscanf@plt>
mov    %eax,%ebp
mov    0x2e9f(%rip),%r15
xor    %eax,%eax
cmp    (%r15),%ebp
cmove  %eax,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <fscanf@plt>
mov    %eax,%ebx
cmp    (%r15),%eax
mov    $0x0,%eax
cmove  %eax,%ebx
add    %ebp,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
mov    0x8(%rsp),%rdx
call   1030 <fscanf@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
mov    $0x0,%eax
cmove  %eax,%ebp
xor    %r13d,%r13d
add    %ebx,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rdx
call   1030 <fscanf@plt>
cmp    (%r15),%eax
cmove  %r13d,%eax
add    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i32 0
define i32 @read_line(i32* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
%13 = load i32*, i32** %6
%14 = load i8*, i8** %7
%15 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 %15, i32* %12
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %5
br label %21
19: ; preds = %5
%20 = load i32, i32* %12
br label %21
21: ; preds = %19, %18
%22 = phi i32 [ 0, %18 ], [ %20, %19 ]
%23 = load i32, i32* %11
%24 = add nsw i32 %23, %22
store i32 %24, i32* %11
%25 = load i32*, i32** %6
%26 = load i8*, i8** %8
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 %27, i32* %12
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %21
br label %33
31: ; preds = %21
%32 = load i32, i32* %12
br label %33
33: ; preds = %31, %30
%34 = phi i32 [ 0, %30 ], [ %32, %31 ]
%35 = load i32, i32* %11
%36 = add nsw i32 %35, %34
store i32 %36, i32* %11
%37 = load i32*, i32** %6
%38 = load i8*, i8** %9
%39 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %38)
store i32 %39, i32* %12
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %33
br label %45
43: ; preds = %33
%44 = load i32, i32* %12
br label %45
45: ; preds = %43, %42
%46 = phi i32 [ 0, %42 ], [ %44, %43 ]
%47 = load i32, i32* %11
%48 = add nsw i32 %47, %46
store i32 %48, i32* %11
%49 = load i32*, i32** %6
%50 = load i8*, i8** %10
%51 = call i32 @fscanf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %50)
store i32 %51, i32* %12
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %45
br label %57
55: ; preds = %45
%56 = load i32, i32* %12
br label %57
57: ; preds = %55, %54
%58 = phi i32 [ 0, %54 ], [ %56, %55 ]
%59 = load i32, i32* %11
%60 = add nsw i32 %59, %58
store i32 %60, i32* %11
%61 = load i32, i32* %11
ret i32 %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i32 0
define i32 @read_line(i32* nocapture %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
%9 = select i1 %8, i32 0, i32 %6
%10 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
%13 = select i1 %12, i32 0, i32 %10
%14 = add nsw i32 %13, %9
%15 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
%18 = select i1 %17, i32 0, i32 %15
%19 = add nsw i32 %14, %18
%20 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
%23 = select i1 %22, i32 0, i32 %20
%24 = add nsw i32 %19, %23
ret i32 %24
}