#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int sscanf(char *, char *, int *);
void get_answer(int sd, char *buf) {
  int code;
  sleep(1);
  memset(buf, 0, 1024);
  recv(sd, buf, 1024, 0);
  printf("%s", buf);
  if (sscanf(buf, "%d %*s", &code) == 1) {
    if (code >= 400) {
      printf("Error! Command failed!\n");
      exit(1);
    } else {
      return;
    }
  }
}


x86 assembly (clang, -O0):
<get_answer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11f5 <get_answer+0x95>
cmpl   $0x190,-0x14(%rbp)
jl     11f0 <get_answer+0x90>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11f5 <get_answer+0x95>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_answer>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe49(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11d6 <get_answer+0x66>
cmpl   $0x190,0x4(%rsp)
jge    11dd <get_answer+0x6d>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%d %*s\00"
@.str.2 = [24 x i8] c"Error! Command failed!\0A\00"
define void @get_answer(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i32 @sleep(i32 1)
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = load i32, i32* %3
%10 = load i8*, i8** %4
%11 = call i32 @recv(i32 %9, i8* %10, i32 1024, i32 0)
%12 = load i8*, i8** %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %4
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* %5
%19 = icmp sge i32 %18, 400
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
br label %24
24: ; preds = %23, %2
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"%d %*s\00"
@str = [23 x i8] c"Error! Command failed!\00"
define void @get_answer(i32 %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @sleep(i32 1)
%6 = tail call i32 @memset(i8* %1, i32 0, i32 1024)
%7 = tail call i32 @recv(i32 %0, i8* %1, i32 1024, i32 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 399
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
ret void
}