#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 */
char *gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int main(void) {
  char buf[100];
  int result = 0;
  if (gets(buf) != buf) {
    printf("gets: read error: %m\n");
    result = 1;
  } else if (strchr(buf, '\n') != NULL) {
    printf("newline not stripped: \"%s\"\n", buf);
    result = 1;
  } else if (strcmp(buf, "foo") != 0) {
    printf("read mismatch: expected \"%s\", got \"%s\"\n", "foo", buf);
    result = 1;
  }
  if (gets(buf) != buf) {
    printf("gets: read error: %m\n");
    result = 1;
  } else if (strchr(buf, '\n') != NULL) {
    printf("newline not stripped: \"%s\"\n", buf);
    result = 1;
  } else if (strcmp(buf, "bar") != 0) {
    printf("read mismatch: expected \"%s\", got \"%s\"\n", "bar", buf);
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     1189 <main+0x49>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    1203 <main+0xc3>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11bf <main+0x7f>
lea    -0x70(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    11fe <main+0xbe>
lea    -0x70(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f9 <main+0xb9>
lea    -0x70(%rbp),%rdx
lea    0xe52(%rip),%rdi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    11fe <main+0xbe>
jmp    1203 <main+0xc3>
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
je     1233 <main+0xf3>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    12ad <main+0x16d>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1269 <main+0x129>
lea    -0x70(%rbp),%rsi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    12a8 <main+0x168>
lea    -0x70(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     12a3 <main+0x163>
lea    -0x70(%rbp),%rdx
lea    0xda8(%rip),%rdi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x74(%rbp)
jmp    12a8 <main+0x168>
jmp    12ad <main+0x16d>
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
cmp    %rbx,%rax
je     1166 <main+0x26>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bb <main+0x7b>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118b <main+0x4b>
lea    0xe97(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bb <main+0x7b>
lea    0xea0(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     123c <main+0xfc>
lea    0xe8c(%rip),%rdi
lea    0xe81(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1060 <gets@plt>
cmp    %rbx,%rax
je     11dd <main+0x9d>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122e <main+0xee>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1202 <main+0xc2>
lea    0xe20(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122e <main+0xee>
lea    0xe55(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1233 <main+0xf3>
lea    0xe19(%rip),%rdi
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11c0 <main+0x80>

LLVM IR (-O0):
@.str = [22 x i8] c"gets: read error: %m\0A\00"
@.str.1 = [28 x i8] c"newline not stripped: \22%s\22\0A\00"
@.str.2 = [4 x i8] c"foo\00"
@.str.3 = [40 x i8] c"read mismatch: expected \22%s\22, got \22%s\22\0A\00"
@.str.4 = [4 x i8] c"bar\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i8* @gets(i8* %4)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = icmp ne i8* %5, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %26
10: ; preds = %0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = call i32* @strchr(i8* %11, i8 signext 10)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %25
17: ; preds = %10
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24, %14
br label %26
26: ; preds = %25, %8
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i8* @gets(i8* %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%30 = icmp ne i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %49
33: ; preds = %26
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%35 = call i32* @strchr(i8* %34, i8 signext 10)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %38)
store i32 1, i32* %3
br label %48
40: ; preds = %33
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %45)
store i32 1, i32* %3
br label %47
47: ; preds = %44, %40
br label %48
48: ; preds = %47, %37
br label %49
49: ; preds = %48, %31
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [22 x i8] c"gets: read error: %m\0A\00"
@.str.1 = [28 x i8] c"newline not stripped: \22%s\22\0A\00"
@.str.2 = [4 x i8] c"foo\00"
@.str.3 = [40 x i8] c"read mismatch: expected \22%s\22, got \22%s\22\0A\00"
@.str.4 = [4 x i8] c"bar\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i8* @gets(i8* %2)
%4 = icmp eq i8* %3, %2
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %0
%8 = call i32* @strchr(i8* %2, i8 signext 10)
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %17
12: ; preds = %7
%13 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %10, %15, %12, %5
%18 = phi i32 [ 1, %5 ], [ 1, %10 ], [ 1, %15 ], [ 0, %12 ]
%19 = call i8* @gets(i8* %2)
%20 = icmp eq i8* %19, %2
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %33
23: ; preds = %17
%24 = call i32* @strchr(i8* %2, i8 signext 10)
%25 = icmp eq i32* %24, null
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %33
28: ; preds = %23
%29 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %33
33: ; preds = %26, %31, %28, %21
%34 = phi i32 [ 1, %21 ], [ 1, %26 ], [ 1, %31 ], [ %18, %28 ]
ret i32 %34
}