#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 */
scalar_t__ _hostname(char const *);
int _hostname_usage();
int getopt(int, char **, char *);
int optind;
int main(int argc, char *argv[]) {
  int o;
  char const *name = NULL;
  while ((o = getopt(argc, argv, "")) != -1)
    switch (o) {
    default:
      return _hostname_usage();
    }
  if (optind + 1 == argc)
    name = argv[optind];
  else if (optind != argc)
    return _hostname_usage();
  return (_hostname(name) == 0) ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     117c <main+0x4c>
mov    $0x0,%al
call   1030 <_hostname_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    11ef <main+0xbf>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    11ac <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x2e4c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    11d2 <main+0xa2>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     11cd <main+0x9d>
mov    $0x0,%al
call   1030 <_hostname_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    11ef <main+0xbf>
jmp    11d2 <main+0xa2>
mov    -0x20(%rbp),%rdi
call   1040 <_hostname@plt>
mov    %rax,%rdx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xec0(%rip),%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     1158 <main+0x28>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <_hostname_usage@plt>
mov    0x2e89(%rip),%rax
movslq (%rax),%rax
lea    0x1(%rax),%ecx
cmp    %ebx,%ecx
jne    116f <main+0x3f>
mov    (%r14,%rax,8),%rdi
jmp    1175 <main+0x45>
cmp    %ebx,%eax
jne    114a <main+0x1a>
xor    %edi,%edi
call   1040 <_hostname@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
add    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
br label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %15 [
]
15: ; preds = %13
%16 = call i32 (...) @_hostname_usage()
store i32 %16, i32* %3
br label %41
17: ; preds = %8
%18 = load i32, i32* @optind
%19 = add nsw i32 %18, 1
%20 = load i32, i32* %4
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i8**, i8*** %5
%24 = load i32, i32* @optind
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
store i8* %27, i8** %7
br label %35
28: ; preds = %17
%29 = load i32, i32* @optind
%30 = load i32, i32* %4
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (...) @_hostname_usage()
store i32 %33, i32* %3
br label %41
34: ; preds = %28
br label %35
35: ; preds = %34, %22
%36 = load i8*, i8** %7
%37 = call i64 @_hostname(i8* %36)
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 0, i32 2
store i32 %40, i32* %3
br label %41
41: ; preds = %35, %32, %15
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @_hostname_usage()
br label %24
7: ; preds = %2
%8 = load i32, i32* @optind
%9 = add nsw i32 %8, 1
%10 = icmp eq i32 %9, %0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
br label %19
15: ; preds = %7
%16 = icmp eq i32 %8, %0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 (...) @_hostname_usage()
br label %24
19: ; preds = %15, %11
%20 = phi i8* [ %14, %11 ], [ null, %15 ]
%21 = tail call i64 @_hostname(i8* %20)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 0, i32 2
br label %24
24: ; preds = %19, %17, %5
%25 = phi i32 [ %6, %5 ], [ %23, %19 ], [ %18, %17 ]
ret i32 %25
}