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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int strlen(char *);
int main() {
  FILE *fp = fopen("test.txt", "r");
  char buf[64], str[32];
  if (!fp)
    return -1;
  if (fgets(buf, sizeof(buf), fp)) {
    sscanf(buf, "ip=%s\n", str);
    printf("str = %s_\n", str);
    printf("buf = %s,strlen(buf) is %d\n", buf, strlen(buf));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <main+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <main+0xae>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f7 <main+0xa7>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1060 <sscanf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xea0(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d2 <main+0x82>
lea    0x20(%rsp),%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d9 <main+0x89>
lea    0xe7c(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rdx
call   1060 <sscanf@plt>
lea    0xe69(%rip),%rdi
xor    %ebx,%ebx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11db <main+0x8b>
mov    $0xffffffff,%ebx
jmp    11db <main+0x8b>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"ip=%s\0A\00"
@.str.3 = [11 x i8] c"str = %s_\0A\00"
@.str.4 = [28 x i8] c"buf = %s,strlen(buf) is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 -1, i32* %1
br label %25
9: ; preds = %0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i64 @fgets(i8* %10, i32 64, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%17 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %20, i32 %22)
br label %24
24: ; preds = %14, %9
store i32 0, i32* %1
br label %25
25: ; preds = %24, %8
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"ip=%s\0A\00"
@.str.3 = [11 x i8] c"str = %s_\0A\00"
@.str.4 = [28 x i8] c"buf = %s,strlen(buf) is %d\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [32 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = icmp eq i32* %3, null
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = call i64 @fgets(i8* %4, i32 64, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%13 = call i32 @strlen(i8* %4)
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %13)
br label %15
15: ; preds = %7, %10, %0
%16 = phi i32 [ -1, %0 ], [ 0, %10 ], [ 0, %7 ]
ret i32 %16
}