#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int seek_definition(int /*<<< orphan*/ *, char *);
scalar_t__ strlen(char *);
int read_string(FILE *f, char *config_path, char *buffer, size_t buffsize) {
  int success;
  long fp;
  uint8_t temp;
  success = seek_definition(f, config_path);
  if (success != 0)
    return success;
  temp = fgetc(f);
  if (temp != 1)
    return 1;
  temp = fgetc(f);
  if (temp != 0)
    return 2;
  while (fgetc(f) != 0)
    ;
  fp = ftell(f);
  if (fgets(buffer, buffsize, f) == NULL)
    return 3;
  fseek(f, fp + strlen(buffer) + 1, SEEK_SET);
  return 0;
}


x86 assembly (clang, -O0):
<read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <seek_definition@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     119d <read_string+0x3d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126e <read_string+0x10e>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
je     11bf <read_string+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    126e <read_string+0x10e>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11e1 <read_string+0x81>
movl   $0x2,-0x4(%rbp)
jmp    126e <read_string+0x10e>
jmp    11e6 <read_string+0x86>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0x0,%eax
je     11fd <read_string+0x9d>
jmp    11e6 <read_string+0x86>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1231 <read_string+0xd1>
movl   $0x3,-0x4(%rbp)
jmp    126e <read_string+0x10e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rdi,%rbx
call   1060 <seek_definition@plt>
test   %eax,%eax
jne    1204 <read_string+0xa4>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
jne    1204 <read_string+0xa4>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    $0x2,%eax
test   %ecx,%ecx
jne    1204 <read_string+0xa4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <fgetc@plt>
test   %eax,%eax
jne    11b0 <read_string+0x50>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11ff <read_string+0x9f>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
xor    %eax,%eax
jmp    1204 <read_string+0xa4>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @read_string(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%13 = load i32*, i32** %6
%14 = load i8*, i8** %7
%15 = call i32 @seek_definition(i32* %13, i8* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %10
store i32 %19, i32* %5
br label %56
20: ; preds = %4
%21 = load i32*, i32** %6
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %5
br label %56
26: ; preds = %20
%27 = load i32*, i32** %6
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 2, i32* %5
br label %56
32: ; preds = %26
br label %33
33: ; preds = %37, %32
%34 = load i32*, i32** %6
%35 = call i32 @fgetc(i32* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
br label %33
38: ; preds = %33
%39 = load i32*, i32** %6
%40 = call i64 @ftell(i32* %39)
store i64 %40, i64* %11
%41 = load i8*, i8** %8
%42 = load i64, i64* %9
%43 = load i32*, i32** %6
%44 = call i32* @fgets(i8* %41, i64 %42, i32* %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 3, i32* %5
br label %56
47: ; preds = %38
%48 = load i32*, i32** %6
%49 = load i64, i64* %11
%50 = load i8*, i8** %8
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %49, %51
%53 = add nsw i64 %52, 1
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %48, i64 %53, i32 %54)
store i32 0, i32* %5
br label %56
56: ; preds = %47, %46, %31, %25, %18
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @read_string(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @seek_definition(i32* %0, i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = tail call i32 @fgetc(i32* %0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = tail call i32 @fgetc(i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10, %13
%14 = tail call i32 @fgetc(i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %13
16: ; preds = %13
%17 = tail call i64 @ftell(i32* %0)
%18 = tail call i32* @fgets(i8* %2, i64 %3, i32* %0)
%19 = icmp eq i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%22 = add i64 %17, 1
%23 = add i64 %22, %21
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %0, i64 %23, i32 %24)
br label %26
26: ; preds = %16, %10, %7, %4, %20
%27 = phi i32 [ 0, %20 ], [ %5, %4 ], [ 1, %7 ], [ 2, %10 ], [ 3, %16 ]
ret i32 %27
}