gets(s) char *s;
{
  char *p;
  extern int cin;
  if (nargs() == 2)
    IEHzap("gets  ");
  p = s;
  while ((*s = cgetc(cin)) != '\n' && *s != '\0')
    s++;
  if (*p == '\0')
    return (0);
  *s = '\0';
  return (p);
}


x86 assembly (clang, -O0):
<gets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <nargs@plt>
cmp    $0x2,%eax
jne    115a <gets+0x2a>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <IEHzap@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    $0x0,%al
call   1030 <cgetc@plt>
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     1199 <gets+0x69>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a9 <gets+0x79>
jmp    11ba <gets+0x8a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1162 <gets+0x32>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d6 <gets+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <gets+0xb4>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gets>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <nargs@plt>
cmp    $0x2,%eax
jne    1152 <gets+0x22>
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <IEHzap@plt>
mov    0x2e9f(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax)
mov    (%r15),%edi
xor    %eax,%eax
call   1030 <cgetc@plt>
mov    %al,(%rbx)
shl    $0x18,%eax
je     117e <gets+0x4e>
cmp    $0xa000000,%eax
je     117e <gets+0x4e>
add    $0x1,%rbx
jmp    1160 <gets+0x30>
cmpb   $0x0,(%r14)
je     1189 <gets+0x59>
movb   $0x0,(%rbx)
jmp    118c <gets+0x5c>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"gets \00"
@cin = external global i32
define i32 @gets(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i32 (...) @nargs()
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @IEHzap to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i8*, i8** %3
store i8* %10, i8** %4
br label %11
11: ; preds = %25, %9
%12 = load i32, i32* @cin
%13 = call i32 (i32, ...) bitcast (i32 (...)* @cgetc to i32 (i32, ...)*)(i32 %12)
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %3
store i8 %14, i8* %15
%16 = sext i8 %14 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %18, %11
%24 = phi i1 [ false, %11 ], [ %22, %18 ]
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %11
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 0, i32* %2
br label %38
34: ; preds = %28
%35 = load i8*, i8** %3
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %2
br label %38
38: ; preds = %34, %33
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [7 x i8] c"gets \00"
@cin = external global i32
define i32 @gets(i8* %0) {
%2 = tail call i32 (...) @nargs()
%3 = icmp eq i32 %2, 2
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @IEHzap to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
br label %7
7: ; preds = %6, %13
%8 = phi i8* [ %14, %13 ], [ %0, %6 ]
%9 = load i32, i32* @cin
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @cgetc to i32 (i32, ...)*)(i32 %9)
%11 = trunc i32 %10 to i8
store i8 %11, i8* %8
%12 = shl i32 %10, 24
switch i32 %12, label %13 [
i32 167772160, label %15
i32 0, label %15
]
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
15: ; preds = %7, %7
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
store i8 0, i8* %8
%19 = ptrtoint i8* %0 to i64
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %15, %18
%22 = phi i32 [ %20, %18 ], [ 0, %15 ]
ret i32 %22
}